A Bug's Life POJ 2492】的更多相关文章

A Bug's Life POJ - 2492 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, indi…
链接: http://poj.org/problem?id=2492 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/J 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> #include<iostream>…
D - A Bug's Life 二分图 并查集 BackgroundProfessor 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, indi…
题目链接 每次给出两个昆虫的关系(异性关系),然后发现这些条件中是否有悖论 就比如说第一组数据 1 2 2 3 1 3 1和2是异性,2和3是异性,然后说1和3是异性就显然不对了. 我们同样可以思考一下这道题如何用带权并查集去做. 首先用r[x]存储的是x与其根节点rx的关系,0代表同性1代表异性(其实反着也一样因为这个关系是一个环状的) 这道题与上一道题唯一的不同是权值不是累加的关系而是相当于二进制的个位,也就是累加结果取%2. 这样就很容易仿照上一道题写出一下代码 #include<iost…
这个题目的写法有很多,用二分图染色也可以写,思路很好想,这里我们用关于并查集的两种写法来做. 题目大意:输入x,y表示x和y交配,然后判断是否有同性恋. 1 带权并查集: 我们可以用边的权值来表示一种关系,比如说 我们可以设权值为1,假如A和B发生关系,B和C发生关系,那么C到A的距离就是2,如果A和C发生关系,那就会产生矛盾,因此A和C是同性. 所以如果x和y可以发生关系,首先x和y必须在一棵树上,并且x和y到跟的距离必须同为奇数或者同为偶数. code: #include<cstdio>…
G - A Bug's Life Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2492 Appoint description: Description BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. H…
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 28651 Accepted: 9331 Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and…
http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭虫(编号1-n)和m对关系,判断是否是出现同性恋的情况. 这题跟食物链的题类似,这里只有两种关系,关系是同性或者异性. 对于每只动物创建两个元素  同性或异性,并用这 2×n个元素建立并查集. 首先判断输入的x和y是否是一个组的.是就flag=1. 然后,如果x和y是一对,那么合并x和y+n,x+n…
http://poj.org/problem?id=2492 题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的. 思路 :这个题跟POJ1703其实差不多,也是需要一个数组来存跟父亲节点的关系,需要两个集合来存是否有关系,在最后稍微变一下形就OK了. #include<iostream> #include<string.h> #include<stdio.h> #include<stdlib.h> using name…
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…