1829 A Bug's Life
2017-11-08 14:14
393 查看
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9223 Accepted Submission(s): 2965
[align=left]Problem Description[/align]
Background
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
Problem
Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.
[align=left]Input[/align]
The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.
[align=left]Output[/align]
The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.
[align=left]Sample Input[/align]
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
[align=left]Sample Output[/align]
[align=left] [/align]
Scenario #1:
Suspicious bugs found!
Scenario#2:
No suspicious bugs found!
Hint
Huge input,scanf is recommended.
[align=left]Source[/align]
TUD Programming Contest 2005, Darmstadt, Germany
View Code
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9223 Accepted Submission(s): 2965
[align=left]Problem Description[/align]
Background
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
Problem
Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.
[align=left]Input[/align]
The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.
[align=left]Output[/align]
The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.
[align=left]Sample Input[/align]
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
[align=left]Sample Output[/align]
[align=left] [/align]
Scenario #1:
Suspicious bugs found!
Scenario#2:
No suspicious bugs found!
Hint
Huge input,scanf is recommended.
[align=left]Source[/align]
TUD Programming Contest 2005, Darmstadt, Germany
1 #include<stdio.h> 2 #include<string.h> 3 int f[3000]; 4 int dis[3000]; 5 6 int find(int x) 7 { 8 int t; 9 if(f[x]==x) 10 return x; 11 12 t=find(f[x]); 13 dis[x]=(dis[x]+dis[f[x]])%2; 14 f[x]=t; 15 return t; 16 17 } 18 19 int make(int x,int y) 20 { 21 int a=find(x); 22 int b=find(y); 23 if(a==b) 24 { 25 if(dis[x]==dis[y]) 26 return 1; 27 return 0; 28 } 29 30 f[a]=b; 31 dis[a]=(dis[x]+dis[y]+1)%2; 32 return 0; 33 34 } 35 36 int main() 37 { 38 //freopen("in.txt","r",stdin); 39 int t,count=1; 40 int n,m; 41 int i,a,b,flag; 42 scanf("%d",&t); 43 while(t--) 44 { 45 scanf("%d%d",&n,&m); 46 memset(dis,0,sizeof(dis)); 47 48 for(i=1;i<=n;i++) 49 f[i]=i; 50 51 flag=0; 52 for(i=0;i<m;i++) 53 { 54 scanf("%d%d",&a,&b); 55 if(make(a,b)) 56 { 57 flag=1; 58 } 59 } 60 61 printf("Scenario #%d:\n",count++); 62 if(flag) 63 printf("Suspicious bugs found!\n"); 64 else 65 printf("No suspicious bugs found!\n"); 66 printf("\n"); 67 } 68 return 0; 69 }
View Code
相关文章推荐
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life 并查集
- A Bug's Life-HDU-1829
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life 并查集
- 杭电1829 A Bug's Life
- hdoj 1829 A Bug's Life 【带权并查集】
- hdu 1829 a bug's life 5.1.1
- HDU1829 A Bug's Life 并查集
- POJ 2492 - A Bug's Life
- A Bug's Life
- POJ 2492 A Bug's Life 并查集
- POJ-2492 A Bug's Life 并查集
- A Bug's Life --- 种类并查集
- POJ 2492--A Bug's Life 【并查集,向量偏移】
- POJ 2492 A Bug's Life 并查集维护类别
- Poj 2492 A Bug's Life
- [POJ 2492]A Bug's Life[并查集]
- POJ2492A Bug's Life【并查集+根节点偏移】
- Pku acm 2492 A Bug's Life数据结构题目解题报告(十)---- 并查集的应用