J - A Bug's Life - poj2492
#include <stdio.h>
#include<algorithm>
using namespace std; const int maxn = ; int f[maxn], relation[maxn];//0表示同性,1表示异性 int Find(int x)
{
int k = f[x];
if(f[x] != x)
{
f[x] = Find(f[x]);
relation[x] = (relation[x]+relation[k])%;
} return f[x];
} int main()
{
int T, t=; scanf("%d", &T); while(T--)
{
int i, N, M, u, v, ru, rv, ok = ; scanf("%d%d", &N, &M); for(i=; i<=N; i++)
f[i] = i, relation[i] = ; for(i=; i<M; i++)
{
scanf("%d%d", &u, &v); if(ok)continue; ru = Find(u), rv = Find(v); if(ru == rv && (relation[v]+)% != relation[u])
ok = ;
else if(ru != rv)
{
f[ru] = rv;
relation[ru] = (-relation[u]+relation[v])%;
}
} if(t != )printf("\n");
printf("Scenario #%d:\n", t++);
if(ok)printf("Suspicious bugs found!\n");
else printf("No suspicious bugs found!\n");
} return ; }
J - A Bug's Life - poj2492的更多相关文章
- J - A Bug's Life 并查集
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- A Bug's Life - poj2492
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- poj1483 It's not a Bug, It's a Feature!
It's not a Bug, It's a Feature! Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 1231 ...
- 【POJ】2096 Collecting Bugs
http://poj.org/problem?id=2096 题意:s个系统n种bug,每天找出一个bug,种类的概率是1/n,系统的概率是1/s.问:每个系统至少找出一个bug:每种类的bug都被找 ...
- ACM - 概率、期望题目 小结(临时)
概率DP求期望大多数都是全期望公式的运用.主要思考状态空间的划分以及状态事件发生的概率.问题可以分为无环和有环两类.无环一类多数比较简单,可以通过迭代或者记忆化搜索完成.有环一类略复杂,可以通过假设方 ...
- 【POJ】【2096】Collecting Bugs
概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...
- Rockethon 2015
A Game题意:A,B各自拥有两堆石子,数目分别为n1, n2,每次至少取1个,最多分别取k1,k2个, A先取,最后谁会赢. 分析:显然每次取一个是最优的,n1 > n2时,先手赢. 代码: ...
- hihocoder 1084 扩展KMP && 2014 北京邀请赛 Justice String
hihocoder 1084 : http://hihocoder.com/problemset/problem/1084 北京邀请赛 Just String http://www.bnuoj.co ...
- CodeChef November Challenge 2014
重点回忆下我觉得比较有意义的题目吧.水题就只贴代码了. Distinct Characters Subsequence 水. 代码: #include <cstdio> #include ...
随机推荐
- log4Net配置详解
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSe ...
- 如何利用C#编写网页投票器程序 如何使用代理来投票 代理IP来投票
一.前言看个图,了解下投票的过程.提交投票信息投票页 ――――――――>投票信息处理页反馈投票结果(请求页)<―――――――(响应页)一般情况下,填写投票信息,然后点提交按钮发送到响应 ...
- iOS RC4加解密算法
-(NSString *)encrypt:(NSString *)string withKey:(NSString *)key{ self.sBox = [[self frameSBox:key] m ...
- 【转】Entity Framework教程
转自:http://www.cnblogs.com/xray2005/category/189491.html Entity Framework系列文章导航 摘要: 本节集合了Entity Fra ...
- SGU 158.Commuter Train
一道简单题. 火车停的位置不是在整点就是在二分之一点,坐标*2,然后枚举火车停的位置,计算总距离即可. code: #include <iostream> #include <cma ...
- seaJs初体验
目录结构 模块定义define define(function(require,exports,module){ //exports可以把方法或属性暴露给外部 exports.name = 'hell ...
- How far away ?
#include<iostream> #include <algorithm> using namespace std; const int M=40010; int dis[ ...
- java.io.serializable
为什么要实现 java.io.serializable? 简单点:“好处就是将来项目如果要做集群的话,就实现java.io.serializable接口”
- jQuery在on绑定事件时,使用Function.prototype.bind上下文,只能用off(event)解绑函数,否则可能导致事件叠加
因为一个bind函数,未解绑成功导致事件叠加,搞了一下午. keyup事件绑定: this.$document.on('keyup', this.keyUp.bind(this)); 原解绑函数: t ...
- QLabel
The QLabel widget provides a text or image display. Content Setting Plain text Pass a QString to s ...