HDU 6016 Count the Sheep
Count the Sheep
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 686 Accepted Submission(s): 295
However, As the result of preparing for tests, luras had no time to practice programing. She didn't want to lose her rating after attending BC. In the end, she found BCround92's writer snowy_smile for help, asking him to leak her something.
Snowy_smile wanted to help while not leaking the problems. He told luras, the best thing to do is to take a good rest according to the following instructions first.
"Imagine you are on the endless grassland where there are a group of sheep. And n sheep of them are silent boy-sheep while m sheep are crying girl-sheep. And there are k friend-relationships between the boy-sheep and girl-sheep.Now You can start from any sheep,
keep counting along the friend relationship. If you can count 4 different sheep, you will exceed 99% sheep-counters and fall asleep."
Hearing of the strange instructions, luras got very shocked. Still, she kept counting. Sure enough, she fell asleep after counting 4 different sheep immediately. And, she overslept and missed the BestCoder in the next day. At a result, she made it that not
losing her rating in the BCround92!!!
However, you don't have the same good luck as her. Since you have seen the 2nd problem, you are possible to have submitted the 1st problem and you can't go back.
So, you have got into an awkward position. If you don't AC this problem, your rating might fall down.
You question is here, please, can you tell that how many different 4-sheep-counting way luras might have before her sleep?
In another word, you need to print the number of the "A-B-C-D" sequence, where A-B, B-C, C-D are friends and A,B,C,D are different.
and as for each case, there are 3 integers in the first line which indicate boy-sheep-number, girl-sheep-number and friend-realationship-number respectively.
Then there are k lines with 2 integers x and y in each line, which means the x-th boy-sheep and the y-th girl-sheep are friends.
It is guaranteed that——
There will not be multiple same relationships.
1 <= T <= 1000
for 30% cases, 1 <= n, m, k <= 100
for 99% cases, 1 <= n, m, k <= 1000
for 100% cases, 1 <= n, m, k <= 100000
there should be 1 integer in the line which represents the number of the counting way of 4-sheep-sequence before luras's sleep.
3 2 2 4 1 1 1 2 2 1 2 2 3 1 3 1 1 2 1 3 1 3 3 3 1 1 2 1 2 2
8 0 2 找规律的题目 先算出来开端是男孩是情况ans,最后的结果是ans*2 四个关系 男-女-男-女 就像一颗只有四层的树,最后一层叶子节点的个数就是答案 #include <iostream> #include <string.h> #include <stdlib.h> #include <math.h> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long int LL; const int maxn=1e5; int n,m,k; vector<int> a[maxn+5]; vector<int> b[maxn+5]; int aa[maxn+5]; int bb[maxn+5]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); int x,y; for(int i=1;i<=n;i++) a[i].clear(); for(int i=1;i<=m;i++) b[i].clear(); memset(aa,0,sizeof(aa)); memset(bb,0,sizeof(bb)); for(int i=1;i<=k;i++) { scanf("%d%d",&x,&y); a[x].push_back(y); b[y].push_back(x); aa[x]++; bb[y]++; } LL ans=0; for(int i=1;i<=n;i++) { LL res=0; for(int j=0;j<aa[i];j++) { res+=(bb[a[i][j]]-1); } ans+=res*(aa[i]-1); } printf("%lld\n",ans*2); } return 0;}
HDU 6016 Count the Sheep的更多相关文章
- (bc 1002)hdu 6016 count the sheep
Count the Sheep Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU - 6016 Count the Sheep 二分图+思维
Count the Sheep 题意: 问题描述 开学翘课固然快乐,然而也有让呃喵抓狂的事,那当然就是考试了!这可急坏了既要翘课又想要打BC还要准备考试的呃喵. 呃喵为了准备考试没有时间刷题,想打BC ...
- hdu 6016 Count the Sheep(思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016 题意:给定男羊和女羊的朋友关系,即给定一个图,问从任意一只羊开始连续数四只不相同的羊的方法数. ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Count the Sheep 思维题
Altough Skipping the class is happy, the new term still can drive luras anxious which is of course b ...
- HDU 5901 Count primes 论文题
Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...
- hdu 3336 Count the string -KMP&dp
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- HDU 6470 Count 【矩阵快速幂】(广东工业大学第十四届程序设计竞赛 )
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6470 Count Time Limit: 6000/3000 MS (Java/Others) ...
- HDU 4372 Count the Buildings
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- tftp32作为dhcp服务器
/******************************************************************* * tftp32作为dhcp服务器 * 每次使用tftp进行文 ...
- Linux中vi的使用
首先,如果vi中出现了方向键变成ABCD的情况,需要卸载默认的vim-common,再安装vim. sudo apt-get remove vim-common sudo apt-get instal ...
- python json.dumps 中文字符乱码
场景:微信公众号推送消息,中文乱码. Date:2017-05-11 10:58:40.033000,\u4f60\u597d 解决方法: python dumps默认使用的ascii编码 ...
- SimplifiedHibernate:简化了的Hibernate
我的目的是实现下Hibernate中增删改查.缓存的核心功能.虽然基本功能实现了,但可能还有好多Bug,欢迎点评拍砖,没准能在一片谩骂声中取得意想不到的进步,:) // DatabaseAccess. ...
- R语言中的标准输入,输出, 错误流
在R中,stdin() 对应标准输入流 , stdout() 对应标准输出流,stderr() 对应标准错误流 1) 从标准输入流中读取数据 在R的交互式环境中, R >a <- read ...
- Sql server中根据存储过程中的部分信息查找存储过程名称的方法【视图和Function】
.查询的语句: select a.id,b.name,a.*,b.* from syscomments a join sysobjects b on a.id=b.id where b.xtype=' ...
- $.ajax的一般用法
$.post.$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax() 一.$.ajax的一般格式 $.ajax({ type: 'POST', url: url , ...
- BootStrap中按钮点击后被禁用按钮的最佳实现方法
//禁用button $('button').addClass('disabled'); // Disables visually $('button').prop('disabled', true) ...
- [转] COM编程总结
一.Com概念 所谓COM(Componet Object Model,组件对象模型),是一种说明如何建立可动态互变组件的规范,此规范提供了为保证能够互操作,客户和组件应遵循的一些二进制和网络标准.通 ...
- Android Bigmap的操作(绘制,裁剪)
绘制 依据某一种颜色绘制Bitmap Bitmap resultBitmap = Bitmap.createBitmap(600,800,Bitmap.Config.ARGB_8888); resul ...