BestCoder Round #92 B题

(今天突然想起来这道题在做的时候卡了cin 而且似乎也有爆int的坑 就拿出来记录一下

((这道题能用来测试输入输出外挂的性能

中文题意不解释

比赛的时候好多人是爆搜的四层

不过还是有更优雅的做法

那就是把每只羊的link数记录下来

然后根据每次数羊的时候的顺序

母羊A 公羊B 母羊C 公羊D

按照这样处理 然后把最后的ans*2就可以了~

 1 #include<bits/stdc++.h>
 2 #define cl(a,b) memset(a,b,sizeof(a))
 3 #define debug(x) cerr<<#x<<"=="<<(x)<<endl
 4 using namespace std;
 5 typedef long long ll;
 6 typedef pair<int,int> pii;
 7
 8 int main()
 9 {
10     int T;
11     scanf("%d",&T);
12     while(T--)
13     {
14         int n,m,k;
15         scanf("%d%d%d",&n,&m,&k);
16         vector<int>a(n+1,0),b(m+1,0);
17         vector<pii>link;
18         for(int i=0;i<k;i++)
19         {
20             int x,y;
21             scanf("%d%d",&x,&y);
22             a[x]++,b[y]++;
23             link.push_back({x,y});
24         }
25         ll ans=0;
26         for(auto i:link)
27         {
28             ll tmp=1ll*(a[i.first]-1)*(b[i.second]-1);
29             //防止出现负数的判断
30             if(tmp<0) continue;
31             ans+=tmp;
32         }
33         printf("%lld\n",ans*2);
34     }
35     return 0;
36 }
37 /*
38
39 3
40 2 2 4
41 1 1
42 1 2
43 2 1
44 2 2
45 3 1 3
46 1 1
47 2 1
48 3 1
49 3 3 3
50 1 1
51 2 1
52 2 2
53
54 */

顺便贴一下6015的代码

 1 #include<bits/stdc++.h>
 2 #define cl(a,b) memset(a,b,sizeof(a))
 3 #define debug(x) cerr<<#x<<"=="<<(x)<<endl
 4 using namespace std;
 5 typedef long long ll;
 6 typedef pair<int,int> pii;
 7
 8 map<string,pii>mp;
 9
10 int main()
11 {
12     int T;
13     scanf("%d",&T);
14     while(T--)
15     {
16         int n;
17         scanf("%d",&n);
18         mp.clear();
19         for(int i=0;i<n;i++)
20         {
21             string str;
22             int value;
23             cin>>str>>value;
24             mp[str].second=max(value,mp[str].second);
25             if(mp[str].first<mp[str].second)
26             {
27                 swap(mp[str].first,mp[str].second);
28             }
29         }
30         int ans=0;
31         for(auto iter:mp)
32         {
33             ans+=((iter.second).first+(iter.second).second);
34         }
35         printf("%d\n",ans);
36     }
37     return 0;
38 }
39 /*
40
41 2
42 5
43 english 1
44 english 2
45 english 3
46 math 10
47 cook 100
48 2
49 a 1
50 a 2
51
52 */

转载于:https://www.cnblogs.com/general10/p/7067595.html

hdu 6016 Count the Sheep相关推荐

  1. HDU - 6016 Count the Sheep(二分图+思维)

    题目链接:点击查看 题目大意:给出左右两个子集分别,再给出k条边,问能否找出四个点,让其连成一条路径 题目分析:一开始看到这个题肯定是个二分图,又因为有边,我就往度数上面想,一看四个点,就在想能不能枚 ...

  2. 【HDU - 6016】Count the Sheep (思维,类似二分图)

    题干: Altough Skipping the class is happy, the new term still can drive luras anxious which is of cour ...

  3. HDU 3336 Count the string(KMP+DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 题意:给你一个字符串,计算其所有前缀在该字符串出现的次数的总和. 思路:next[j]=i,代表 ...

  4. HDU 3336 Count the string KMP

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...

  5. HDU 4588 Count The Carries 数学

    Count The Carries Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  6. Hdu 4916 Count on the path

    意甲冠军:鉴于一棵树的顶点标签为连续1~n,不是每个网上查询a-b最小的圆点标签路径 这题想了好久,如果1为根节点. 首先如果a-b只是根节点1.答案一定是1. 否则我们用fa[i]表示i节点的父亲, ...

  7. HDU 5528 Count a * b

    Count a * b 推式子 f(n)=∑i=0n−1∑j=0n−1n∤ij=n2−∑i=1n∑j=1nn∣ij=n2−∑i=1n∑j=1nngcd(i,n)∣igcd(i,n)j=n2−∑i=1n ...

  8. hdu 4472 Count(递推即dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 代码: #include <cstdio> #include <cstring ...

  9. hdu 4588 Count The Carries 南京邀请赛

    题目意思:求a~b 之间数二进制的和 求  进了多少位. 比如  1-3     01+10+11=22   22->30->110 进了 2位 要寻找规律,发现  加到3的时候为22   ...

最新文章

  1. 消费者关注的 Win8 问题汇总(下)
  2. .NET程序在Linux容器中的演变
  3. 五个你绝不可忽视的HTML5特性
  4. matlab变参传函,什么是传递函数的增益
  5. tempdb 数据文件暴涨
  6. 【数学建模】2021年美赛C题思路(预测模型和图像识别)【含Matlab源码 245期】
  7. 三点确定一个圆的计算方法
  8. for linux pdf转mobi_linux PDF转换为SWF
  9. Oracle EBS系统维护工具
  10. Bokeh—通过plotting绘制图形
  11. 计算一个整数,转换成二进制,里面有多少个1
  12. Hie with the Pie(Floyd+状压dp)
  13. Day13-寻觅踪迹
  14. 怎么样用计算机计算上浮的价格,原价上上涨百分比怎么算
  15. java连接oracle报错ora-12505,Oracle SQL Developer连接报错(ORA-12505)的解决方案(两种)
  16. 【Matplotlib】(一)绘制图像函数
  17. 沃顿上学院自我管理课——米歇尔.奥巴马
  18. Math Program Big-man
  19. 365天挑战LeetCode1000题——Day 117 矩形区域不超过 K 的最大数值和
  20. 控件注册失败原因汇集

热门文章

  1. .NET开发 程序员必备工具 -- Regulator:生成正则表达式工具
  2. 计算机网络——数据帧和数据包的区别
  3. k-d tree算法原理及实现
  4. html5 自动保存 提示,html5+ SQLite提示数据表不存在
  5. android系统存储路径在哪里,Android 手机存储目录
  6. 计算机视觉基础---OpenCV框架与图像插值算法(图像伸缩)cpp+python
  7. Linux学习笔记7
  8. Web MVC模式实现
  9. 理科生的人生感悟-01-时间的短暂 - 父亲 - 火车上的颠沛流离
  10. [ARM] [基础][编译]ARM的浮点功能历史分类和对应的编译选项