HDU - 6016 Count the Sheep(二分图+思维)
题目链接:点击查看
题目大意:给出左右两个子集分别,再给出k条边,问能否找出四个点,让其连成一条路径
题目分析:一开始看到这个题肯定是个二分图,又因为有边,我就往度数上面想,一看四个点,就在想能不能枚举每一条边,因为边的两头就是两个点了,然后这两个点的度数就决定了以当前边为中间边的所有情况了,于是这样写了一发。。感觉没什么问题,就是在中间过程会爆int,记得开longlong就好了,然后最后结果记得乘2,因为跑出样例来发现总是是二分之一的关系,后来想了一下发现是因为每个羊都可以作为起点,然后算出来的那些边反着也可以跑,所以最后答案要乘2
代码:
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e5+100;int boy[N],girl[N];//记录度数 int a[N],b[N];int main()
{
// freopen("input.txt","r",stdin);
// ios::sync_with_stdio(false);int w;cin>>w;while(w--){memset(girl,0,sizeof(girl));memset(boy,0,sizeof(boy));int n,m,k;scanf("%d%d%d",&n,&m,&k);for(int i=1;i<=k;i++){scanf("%d%d",a+i,b+i);boy[a[i]]++;girl[b[i]]++;}LL ans=0;for(int i=1;i<=k;i++)ans+=(boy[a[i]]-1)*(girl[b[i]]-1);printf("%lld\n",ans*2);}return 0;
}
HDU - 6016 Count the Sheep(二分图+思维)相关推荐
- hdu 6016 Count the Sheep
BestCoder Round #92 B题 (今天突然想起来这道题在做的时候卡了cin 而且似乎也有爆int的坑 就拿出来记录一下 ((这道题能用来测试输入输出外挂的性能 中文题意不解释 比赛的时候 ...
- 【HDU - 6016】Count the Sheep (思维,类似二分图)
题干: Altough Skipping the class is happy, the new term still can drive luras anxious which is of cour ...
- HDU - 7031 Power Station of Art 思维 + 二分图模型
传送门 文章目录 题意: 思路: 题意: 给你两个完全相同的图,现在两个图的每个点上有一个值valvalval并且有一个颜色colcolcol,颜色只能为红色或黑色,注意两个图只是长得一样,点的权值和 ...
- hdu 5285(染色法判断二分图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5285 解题思路:很明显的是二分图的判定,用染色法即可. 不过这题有一个坑,当n<=1和m=0时要 ...
- 【HDU - 1083 】Courses (二分图)
题干: Consider a group of N students and P courses. Each student visits zero, one or more than one cou ...
- HDU - 奔小康赚大钱(二分图最佳匹配+KM)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- hdu 5247 找连续数(思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5247 找连续数 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 3336 Count the string(KMP+DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 题意:给你一个字符串,计算其所有前缀在该字符串出现的次数的总和. 思路:next[j]=i,代表 ...
- HDU 3336 Count the string KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...
最新文章
- jeecg之弹窗插件lhgdialog小结
- npm install 卡住的时候的处理
- Eclipse: Difference between clean, build and publish
- 图像仿射变换 图像平移 python实现
- 第九届蓝桥杯 乘积尾零
- c++ - 虚函数表
- Hadoop基础【HDFS的shell,客户端操作、上传下载流程】
- matlab powf,科学网—MZDDE中操作数更正 - 张凯元的博文
- workerman入门之GatewayWorker的使用
- 【学习笔记+习题集】字符相关(输入输出流,字典树,AC自动机,后缀自动机)(4598字)(更新至2022.12.28)
- 第1章 计算机组成原理概述
- python接入支付宝接口
- 校招群面及专业面技巧总结(适用产品等非技术岗)
- 互联网+智慧环保建设需求
- 笔记本更换散热风扇及硅胶
- UESToj 1057 秋实大哥与花 ( 线段树
- 百战终破黄金甲,不破楼兰终不还!
- 计算机网络原理笔记 第三章 数据链路层(一)
- 夜访阿里总部:实拍双11背后神秘的程序员!
- javascript DOM小结