POJ 2492
2013-08-09 01:24
106 查看
A Bug's Life
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
Sample Output
Hint
Huge input,scanf is recommended.
Source
TUD Programming Contest 2005, Darmstadt, Germany
并查集,看看在同一集合中的虫子是否同性。
我发现了某位同学的解题报告,顿时被他猥琐至极的行文风格震惊了。。。
请看http://zhan.renren.com/xiaoyantian?gid=3602888498034342481&checked=true
娱乐过后,贴出我的代码:
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 24837 | Accepted: 8087 |
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
并查集,看看在同一集合中的虫子是否同性。
我发现了某位同学的解题报告,顿时被他猥琐至极的行文风格震惊了。。。
请看http://zhan.renren.com/xiaoyantian?gid=3602888498034342481&checked=true
娱乐过后,贴出我的代码:
#include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <map> #include <string> #include <stack> #include <cctype> #include <vector> #include <queue> #include <set> using namespace std; //#define Online_Judge #define outstars cout << "***********************" << endl; #define clr(a,b) memset(a,b,sizeof(a)) #define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++) #define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++) #define REP(i , x , n) for(int i = (x) ; i > (n) ; i--) #define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--) const int MAXN = 2000 + 50; const int maxw = 100 + 20; const int MAXNNODE = 1000000 +10; const long long LLMAX = 0x7fffffffffffffffLL; const long long LLMIN = 0x8000000000000000LL; const int INF = 0x7fffffff; const int IMIN = 0x80000000; #define eps 1e-8 #define mod 1000000007 typedef long long LL; const double PI = acos(-1.0); typedef double D; typedef pair<int , int> pi; int n , p[MAXN] , r[MAXN];///0代表r[i]与i同性, 1代表i与r[i]异性 int find_fa(int x) { int temp = p[x]; if(x == p[x])return x; p[x] = find_fa(p[x]); r[x] = r[temp] == 0 ? r[x] : 1 - r[x]; return p[x]; } void init() { FORR(i , 0 , n) { p[i] = i; r[i] = 0; } } int Union(int x , int y , int rx , int ry) { p[ry] = p[rx] ; r[ry] = r[x] == r[y] ? 1 : 0; } int main() { //ios::sync_with_stdio(false); #ifdef Online_Judge freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif // Online_Judge int i , j , m , a , b , rx , ry , flag , cnt = 1 , t; scanf("%d" , &t); while(t--) { flag = 0; scanf("%d%d" , &n , &m); init(); while(m--) { scanf("\n%d %d" , &a ,&b); rx = find_fa(a) , ry = find_fa(b); if(rx == ry && r[a] == r[b])flag = 1;///在同一个集合且性别相同 else Union(a , b , rx ,ry); } if(flag==1) printf("Scenario #%d:\nSuspicious bugs found!\n",cnt++); else printf("Scenario #%d:\nNo suspicious bugs found!\n",cnt++); printf("\n"); } return 0; }
相关文章推荐
- POJ 2492 A Bug's Life
- POJ 1703 1182 2492 一类并查集题目-(类别偏移量)
- POJ 2492 A Bug's Life
- poj 2492 生物实验
- POJ 2492(2013.9.21周赛E题:并查集)
- poj 2492 A Bug's Life(带类别偏移并查集)
- POJ 2492[带权并查集]
- poj 2492 A Bug's Life(并查集)
- (简单) POJ 2492 A Bug's Life,二分染色。
- poj 2492 A Bug's Life
- POJ - 2492 并查集
- POJ 2492 A Bug's Life
- poj 并查集 - 2492 A Bug's Life
- POJ 2492 A Bug&#39;s Life
- POJ 2492 A Bug's Life【并查集的简单应用同类的判断】
- POJ 2492 (并查集)
- poj 2492 A Bug's Life
- POJ 3928 & hdu 2492 & Uva1428 PingPong 【树状数组】
- POJ 2492 A Bug's Life
- poj_2492 A Bug's Life (并查集)