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 ...
随机推荐
- (转载)loadrunner简单使用——HTTP,WebService,Socket压力测试脚本编写
原文出处:http://ajita.iteye.com/blog/1728243/ 先说明一下,本人是开发,对测试不是特别熟悉,但因工作的需要,也做过一些性能测试方面的东西.比较久之前很简单的用过,最 ...
- Linux运行C#程序
首先需要安装mono 安装教程http://www.cnblogs.com/aixunsoft/p/3422099.html 然后 用终端执行C#程序就可以了,mono 程序文件名 可以直接执行win ...
- 分享一个nodejs写的小论坛
引言:作为一个前端小菜鸟,最近迷上了node,于是乎空闲时间,为了练练手写了一个node的小社区,关于微信小程序的,欢迎大家批评指导. 项目架构部分 一.前端架构 作为一个写样式也得无聊的前端狮,我偷 ...
- SGU 221.Big Bishops(DP)
题意: 给一个n*n(n<=50)的棋盘,放上k个主教(斜走),求能放置的种类总数. Solution : 同SGU 220,加个高精度就好了. code #include <iostre ...
- Android三种菜单简介
Android的菜单分为三种类型:选项菜单(Option Menu).上下文菜单(Context Menu).子菜单(Sub Menu). 一.选项菜单 用户点击设备上的菜单按钮(Menu),触发事件 ...
- Getopt::Long 模块的简单使用
用法简介 1.带值参数传入程序内部 ※参数类型:整数, 浮点数, 字串 GetOptions( 'tag=s' => \$tag ); ‘=’表示此参数一定要有参数值, 若改用’:'代替表示参数 ...
- How far away ?
#include<iostream> #include <algorithm> using namespace std; const int M=40010; int dis[ ...
- JS call和apply用法(转)
每个JavaScript函数都会有很多附属的(attached)方法,包括toString().call()以及apply().听起来,你是否会 感到奇怪,一个函数可能会有属于它自己的方法,但是记住, ...
- CreateJS第0章- Canvas基础
最近网页游戏比较火,以前做过一些小游戏,但是过段时间就都忘了,今天在这里记录一下学习过程,以备后用.做网页游戏有很多种框架,我是flash程序用Adobe出品的CreateJS最容易.基本上继承了fl ...
- jQuery height()、innerHeight()、outerHeight()函数的区别
参考: http://www.365mini.com/tech 函数 高度范围 jQuery版本 支持写操作 height() height 1.0+ 1.0+ innerHeight() heigh ...