POJ 2492 虫子交配
2016-07-08 09:32
218 查看
A Bug’s Life
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 33828 Accepted: 11077
Description
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.
Input
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.
Output
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.
Sample Input
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
Sample Output
Scenario #1:
Suspicious bugs found!
Scenario #2:
No suspicious bugs found!
Hint
Huge input,scanf is recommended.
Source
TUD Programming Contest 2005, Darmstadt, Germany
【分析】
这道题用补集做。
做的我欲仙欲死
我要告诉大家
能用flag不要用break
pity
【代码】
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 33828 Accepted: 11077
Description
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.
Input
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.
Output
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.
Sample Input
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
Sample Output
Scenario #1:
Suspicious bugs found!
Scenario #2:
No suspicious bugs found!
Hint
Huge input,scanf is recommended.
Source
TUD Programming Contest 2005, Darmstadt, Germany
【分析】
这道题用补集做。
做的我欲仙欲死
我要告诉大家
能用flag不要用break
pity
【代码】
//poj 2492 #include<iostream> #include<cstdio> #include<vector> #include<cstring> #include<algorithm> #define fo(i,j,k) for(i=j;i<=k;i++) using namespace std; int T,n,m; int father[2000001]; int find(int x) { if(x==father[x]) return x; father[x]=find(father[x]); return father[x]; } int main() { int i,j,k,x,y; bool flag; scanf("%d",&T); fo(k,1,T) { flag=0; scanf("%d%d",&n,&m); for(i=1;i<=n+n;i++) father[i]=i; fo(i,1,m) { scanf("%d%d",&x,&y); int r1=find(x); int r2=find(y); if(r1==r2) flag=1; father[r1]=find(y+n); father[r2]=find(x+n); } if(flag) printf("Scenario #%d:\nSuspicious bugs found!\n\n",k); else printf("Scenario #%d:\nNo suspicious bugs found!\n\n",k); } return 0; }
相关文章推荐
- 1611:The Suspects
- 作业四,1001
- 作业四1002
- 作业四1003
- 练习四1005
- 最小权值和
- HDU-1213-How Many Tables
- Longest Consecutive Sequence,Distinct Subsequences,Interleaving String,Scramble String
- 并查集_POJ 1182_食物链
- SARS病毒传染 并查集
- HDU 1213
- CSU1307 并查集+SPFA
- 并查集
- BestWiring——Kruskal算法&并查集
- 1611:The Suspects
- 并查集示例1
- 并查集(union-find)学习报告
- poj3728
- HDU-1233 还是畅通工程(最小生成树&并查集)
- Simon-【深入理解数据结构】有根树的不同实现① —— 并查集