POJ 2492
来源:互联网 发布:centos开启snmp 编辑:程序博客网 时间:2024/06/16 07:34
A Bug's Life
Time Limit: 10000MS Memory Limit: 65536KTotal Submissions: 24837 Accepted: 8087
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.
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
23 31 22 31 34 21 23 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 1000000007typedef 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 && poj 1703
- POJ 2492
- POJ 2492
- poj-2492
- POJ 2492
- POJ 2492
- poj 2492
- POJ 2492 2-sat
- poj 2492 生物实验
- POJ-2492(DFS)
- POJ 2492 解题报告
- POJ 2492 虫子交配
- POJ
- poj
- POJ
- POJ
- poj
- poj
- Android.mk
- 发一些我在学习erlang过程中给予我帮助的 博客
- Java多线程——2 ThreadLocal
- 【Sesame】实现MySQL底层存储对接
- C++_直接插入排序
- POJ 2492
- C++资源之不完全导引(完整版)
- POJ 1001 求高精度幂
- C++_直接插入排序(纯C版)
- TortoiseSVN使用Repository UUID doesn't match expected 解决办法
- 五分钟讲清楚UML
- HDU 3016
- C++_快速排序
- 【设计模式】学习笔记7:单件模式(Singleton)