A Bug's Life - poj2492
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
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
Suspicious bugs found!
Scenario #2:
No suspicious bugs found!
Hint
Huge input,scanf is recommended.
#include<iostream>
#include<cstdio> using namespace std; #define N 2010 int f[N], v[N]; // v 数组存的是下标与其根结点的性别状态,0代表同性,1代表异性,f存的是下标的根结点 int found(int x)
{
int k = f[x]; if(f[x] != x)
{
f[x] = found(k); // 寻找根结点
v[x] = (v[x]+v[k])%; // 根结点在变,v数组其与根结点的状态也要变,如果与其原先
}
return f[x];
}
int main()
{
int t, a, b, n, m; cin >> t; for(int i = ; i <= t; i++)
{
cin >> n >> m;
int ok = ; for(int j = ; j <= n; j++)
f[j] = j, v[j] = ; while(m--)
{
cin >> a >> b; if(ok) continue; int na = found(a), nb = found(b); if(na == nb && (v[a]+)% != v[b]) // 如果两个数之前已经有了联系,并且联系不是正常的,同性恋(相等代表正常,ok置为1,就有可疑对象发现
ok = ;
if(na != nb)
{
f[na] = nb; v[na] = (-v[a]+v[b])%; // 如果之前两个没有联系,就把两个数的根结点联系起来(根据已知其与根结点状态~
}
}
if(i != )
printf("\n");
printf("Scenario #%d:\n", i);
if(ok)
printf("Suspicious bugs found!\n");
else
printf("No suspicious bugs found!\n");
}
printf("\n"); // 格式控制,虽然我也没看见题上哪句话是这意思
return ;
}
之前一直不太懂什么意思,什么算同性恋,是opposite gender?醉了,是与当前已知条件矛盾。一个人和另一个人有关系就在一个树上,有点关系的都在一条树上。一棵树上应该与根结点状态一致,否则就是同性恋,不在一棵树上随便状态。。和食物链是不是一样,但是我根本都没想食物链的事。。
头脑简单四肢发达的生物,想不出来一直想~
A Bug's Life - poj2492的更多相关文章
- J - A Bug's Life - poj2492
这个题目很有意思啊,有一些bug生物(肯定是程序员养的),有人观察他们的生活习惯,观察他们之间是否有同性恋关系,比如ab发生关系,bc发生关系,ab发生关系...产生了同性恋了,你需要判断一下这种关系 ...
- [poj2492]A Bug's Life(并查集+补集)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 34678 Accepted: 11339 D ...
- POJ2492 A Bug's Life
Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 33833 Accepted: 11078 Description Ba ...
- poj2492 A Bug's Life【并查集】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assume ...
- poj2492 A Bug's Life(带权并查集)
题目链接 http://poj.org/problem?id=2492 题意 虫子有两种性别,有n只虫子,编号1~n,输入m组数据,每组数据包含a.b两只虫子,表示a.b为不同性别的虫子,根据输入的m ...
- POJ2492:A Bug's Life(种类并查集)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 45757 Accepted: 14757 题 ...
- POJ2492 A Bug's Life —— 种类并查集
题目链接:http://poj.org/problem?id=2492 A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Su ...
- POJ2492 A Bug's Life 带权并查集
分析:所谓带权并查集,就是比朴素的并查集多了一个数组,记录一些东西,例如到根的距离,或者和根的关系等 这个题,权数组为relation 代表的关系 1 和父节点不同性别,0,和父节点同性别 并查集一 ...
- poj2492 A Bug's Life【基础种类并查集】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298148.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
随机推荐
- LATERAL VIEW 语法
LATERAL VIEW 使用语法 原文链接: https://www.deeplearn.me/2892.html select a.id, b.son_order_path from f_jz_c ...
- java.io.NotSerializableException错误解决方法
运行tomcat下面的 ssh项目,启动,打开某页面(让session起作用),停止:再启动,有可能会报类似如下的错误: org.apache.catalina.session.StandardMan ...
- 聊聊redis的监控工具
序 本文主要研究一下redis的监控工具 redis-stat redis-stat是一个比较有名的redis指标可视化的监控工具,采用ruby开发,基于redis的info命令来统计,不影响redi ...
- jQuery将字符串转换为数字
1:parseInt(string) parseInt("1234blue"); //returns 1234 parseInt("123"); //retu ...
- .Net core 2.0 利用Attribute获取MVC Action来生成菜单
最近在学习.net core的同时将老师的MVC5项目中的模块搬过来用,其中有一块就是利用Attribute来生成菜单. 一·首先定义Action实体 /// <summary> /// ...
- 终端参数上报后,平台通过tcp协议接收到相应数据并处理。
终端将终端参数以json格式的数据发送至平台.终端上电后上报,可以不认证直接上报. 实现流程如下. 1.设置终端参数上报的协议类型,例如:0x0000. public static final int ...
- 史上最全最常用的正则表达式(转自微信公众号:javascript)
很多不太懂正则的朋友,在遇到需要用正则校验数据时,往往是在网上去找很久,结果找来的还是不很符合要求.所以我最近把开发中常用的一些正则表达式整理了一下,在这里分享一下.给自己留个底,也给朋友们做个参考. ...
- java_第一年_JDBC(3)
事务 我们在通过JDBC连接数据库并开始交互时,默认情况下是自动提交的,有时由于为了保持业务流程的完整性.提高性能或是使用分布式事务,需要启动支持事务,此时的方法是调用Connection对象的set ...
- [SOL] #148. 数字格子问题
说实话这题确实挺菜的... 废话少说,直接上代码^O^ Code: #include <bits/stdc++.h> using namespace std; inline int rea ...
- 修改ps工具栏字体大小
修改ps工具栏字体大小 先改电脑分辨率或者改首选项--界面---文字,退出后,重新打开,但你会发现问题还是没解决,我们接着往下 找到文件夹安装目录下的photoshops.exe启动文件(查找方法 ...