Problem 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.

 
 
大致题意:
  检查一堆数据中是否有同性恋,找出主要矛盾是如果1交配2,2交配3,而1又交配3,则矛盾。找到一组就行。
解题思路:
  用并查集做元素关系判断,主要建立余数体系;
 
 #include <cstdio>
using namespace std;
int f[+],num[+],t,n,m,a,b,fa,fb;
int sf(int x){
if(x==f[x]) return x;
else {
int fx=sf(f[x]);
num[x]=(num[x]+num[f[x]])%;
return f[x]=fx;
}
}
int main(){
scanf("%d",&t);
for(int k=;k<=t;k++){
printf("Scenario #%d:\n",k);
scanf("%d%d",&n,&m); bool flag=;
for(int i=;i<=n;i++) f[i]=i,num[i]=;
for(int i=;i<=m;i++){
scanf("%d%d",&a,&b);
if(flag){
fa=sf(a); fb=sf(b);
if(fa==fb){ if((num[a]-num[b]+)%!=) flag=;}//避免负数
else f[fb]=fa,num[fb]=(num[a]-num[b]++)%;
}
}
if(flag) puts("No suspicious bugs found!\n");
else puts("Suspicious bugs found!\n");
} return ;
}

HDU 1829 - A Bug's Life的更多相关文章

  1. HDU 1829 A Bug's Life (种类并查集)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Oth ...

  2. hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them

    http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...

  3. hdu 1829 A Bug's Life(分组并查集(偏移量))

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. 【进阶——种类并查集】hdu 1829 A Bug's Life (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany

    先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组 ...

  5. hdu 1829 A Bug's Life(并查集)

                                                                                                    A Bu ...

  6. HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  7. HDU 1829 A Bug's Life(种类并查集)

    思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector ...

  8. hdu 1829 &amp;poj 2492 A Bug&#39;s Life(推断二分图、带权并查集)

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  9. HDU 1829/POJ 2492 A Bug's Life

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. Sqlserver系列(二) 模糊查询 like

    通配符 % 匹配零个或多个字符 _ 匹配单个字符 []  指定范围 ([a-f]) 或集合 ([abcdef]) 中的任何单个字符. [^] 不属于指定范围 ([a-f]) 或集合 ([abcdef] ...

  2. ASP.NET MVC请求特殊静态文件返回404 Not Found

    今天在请求静态的json档案以及woff2档案,会返回404错误,需要在Web.Config里修改: <system.webServer> <modules> <remo ...

  3. php 格式

    $abc = ($_POST[' : strtotime($_POST['start_time']); 解析:判断接收的数据是否为0,如果等于0赋值0,若不等于,则赋值获取的数值. strtotime ...

  4. 复习:IPC机制

    一.为什么需要IPC机制 当我们开启多个进程的时候,我们有时需要和各个进程进行交互.但是进程间的交互就不能够共享对象(就是进程A中创建了一个对象,进程B中的类或者方法不能够直接使用,需要用到IPC机制 ...

  5. 解决ERROR C2011: 'FD_SET' : 'STRUCT' TYPE REDEFINITION问题

    在socket编程的过程中头文件中 #include <windows.h> #include "stdafx.h" #include "WinSock2.h ...

  6. python运维开发(十一)----线程、进程、协程

    内容目录: 线程 基本使用 线程锁 自定义线程池 进程 基本使用 进程锁 进程数据共享 进程池 协程 线程 线程使用的两种方式,一种为我们直接调用thread模块上的方法,另一种我们自定义方式 方式一 ...

  7. C#实现在winfrom程序中下载文件

    //下载文件//downlaodUrl 系统路径如:http://xxx.xxx.xxx/UpFile/kaoqin.doc//fileName 自定义文件名字加后缀(如:考勤.doc)//fileP ...

  8. Android下EditText中的字体不统一问题

    Android下EditText中的字体不统一问题 好久没写,今天心情好略记下解决的某bug 在一个登录界面有帐号和密码两个EditText,但是却发现两个EditText的hint的英文字体不同,看 ...

  9. 【Xamarin挖墙脚系列:Xamarin正式发布了IOS的模拟器在Windows下】

    xamarin 的发展越来越迅速.如果还感觉这玩意儿是个鸡肋,辣么请跟的上时代吧 . (额,对微软产品有严重偏见的请绕行..............其实你可以看看.net 基金会现有的开源项目再说不开 ...

  10. Ruiy classicsQuotations

    1,IT界,许多人会称自己为菜鸟,而每只菜鸟都会有鹰的梦想; 2,把做十件事精力用来做一件事情,你事业就经典了;