HDU
来源:互联网 发布:java中根号怎么表示 编辑:程序博客网 时间:2024/05/22 12:50
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016点击打开链接
Count the Sheep
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1334 Accepted Submission(s): 610
Problem Description
Altough Skipping the class is happy, the new term still can drive luras anxious which is of course because of the tests! Luras became worried as she wanted to skip the class, as well as to attend the BestCoder and also to prepare for tests at the same time.
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.
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.
Input
The first line is an integer T which indicates the case number.
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
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
Output
As for each case, you need to output a single line.
there should be 1 integer in the line which represents the number of the counting way of 4-sheep-sequence before luras's sleep.
there should be 1 integer in the line which represents the number of the counting way of 4-sheep-sequence before luras's sleep.
Sample Input
32 2 41 11 22 12 23 1 31 12 13 13 3 31 12 12 2
Sample Output
802
思维好题
男女羊构成的是二分图
暴力判断每个边能否延伸出一男一女
#include <stdio.h>#include <string.h>#include <iostream>#include <vector>#include <queue>using namespace std;int a[111111];int b[111111];int ea[111111];int eb[111111];int main(){ int t=0; scanf("%d",&t); while(t--) { int n,m,k; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(ea,0,sizeof(ea)); memset(eb,0,sizeof(eb)); scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=k;i++) { scanf("%d%d",&ea[i],&eb[i]); a[ea[i]]++; b[eb[i]]++; } long long int sum=0; for(int i=1;i<=k;i++) { sum+=(a[ea[i]]-1)*(b[eb[i]]-1); } printf("%lld\n",sum*2); }}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 用C语言来编写51单片机液晶显示屏幕的修改密码功能
- 暑期集训之立方求和
- python之find_all
- 录制视频
- spring aop中的After throwing增强问题
- HDU
- gson解析xml
- Batch Gradient Descent(python)
- [LeetCode] 238. Product of Array Except Self
- SSM框架下利用AJAX传递数据到Controller的一些方式
- 图像的遍历
- Java服务端过滤敏感词的思路
- Glusterfs学习笔记
- POJ2186-Popular Cows