A Bug's Life____并查集
English preparation:
falsify 伪造;篡改;歪曲;证明...虚假
the sexual behavior of a rare species of bugs. 一种稀有昆虫的性行为。
the number of scenarios 场景数量
consecutively 连续地
趣语:
这个时代,是个雷人的时代。凤姐的出现,让我们对自己的审美观产生了怀疑;
著姐的降临,使我们对自己的性取向做出了更正。而如今,bug们被同性恋了,这直接就是商人们为了扩大HS产业的炒作。
哪一天,也许你也被变态了,被脑残了。。。
题目大意:给出n条虫子,m个配对(男<->女)的情况,问数据有没有错误(出现同性配对)?
Reference:
1.https://blog.csdn.net/freezhanacmore/article/details/8799495
2.https://www.cnblogs.com/dongsheng/archive/2012/08/08/2627917.html
3.https://blog.csdn.net/pku_Coder/article/details/53520171
codes:
#include<cstdio>
#include<iostream>
const int maxn=+;
int p[maxn]; //记录父节点
int r[maxn]; //记录与父节点关系, 0 同类, 1异类 int find(int x)
{
if(x==p[x]) return x; int t=p[x];
p[x]=find(p[x]);
r[x]=(r[x]+r[t])%; //每次回溯更新一次父节点,相应更新关系
return p[x];
} void Union(int x,int y)
{
int fx=find(x);
int fy=find(y); p[fx]=fy; //任意
r[fx]=(r[x]++r[y])%; //r[]没有方向.我就是这一步的关系,这一个式子,这一处关节没有搞明白!
}
void set(int n)
{
for(int i=;i<=n;i++)
{
p[i]=i;
r[i]=;
}
} int main()
{
int T;
scanf("%d",&T);
for(int i=;i<=T;i++)
{
int n,m;
scanf("%d%d",&n,&m);
set(n);
int x,y;
bool flag=true;
while(m--)
{
scanf("%d%d",&x,&y); //本应不同类
if(find(x)==find(y))
{
if(r[x]==r[y]) //如果同类
{
flag=false;
continue;
}
}
else Union(x,y);
}
printf("Scenario #%d:\n",i);
if(flag) printf("No suspicious bugs found!\n");
else printf("Suspicious bugs found!\n");
printf("\n");
}
return ;
}
A Bug's Life____并查集的更多相关文章
- hdu 1829 A Bug's Life(并查集)
A Bu ...
- J - A Bug's Life 并查集
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- nyoj 209 + poj 2492 A Bug's Life (并查集)
A Bug's Life 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Background Professor Hopper is researching th ...
- poj 2492A Bug's Life(并查集)
/* 目大意:输入一个数t,表示测试组数.然后每组第一行两个数字n,m,n表示有n只昆虫,编号从1—n,m表示下面要输入m行交配情况,每行两个整数,表示这两个编号的昆虫为异性,要交配. 要求统计交配过 ...
- 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条臭 ...
- POJ 2492 A Bug's Life 并查集的应用
题意:有n只虫子,每次给出一对互为异性的虫子的编号,输出是否存在冲突. 思路:用并查集,每次输入一对虫子后就先判定一下.如果两者父亲相同,则说明关系已确定,再看性别是否相同,如果相同则有冲突.否则就将 ...
- poj2492_A Bug's Life_并查集
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 34947 Accepted: 11459 D ...
- [poj2492]A Bug's Life(并查集+补集)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 34678 Accepted: 11339 D ...
- POJ 2492 A Bug's Life (并查集)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 30130 Accepted: 9869 De ...
随机推荐
- Maven项目pom文件的节点释意
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- spark读取文件机制 源码剖析
Spark数据分区调研 Spark以textFile方式读取文件源码 textFile方法位于 spark-core_2.11/org.apache.spark.api.java/JavaSparkC ...
- 1236 - Pairs Forming LCM
1236 - Pairs Forming LCM Find the result of the following code: long long pairsFormLCM( int n ) { ...
- 全文检索框架---Lucene
一.什么是全文检索 1.数据分类 我们生活中的数据总体分为两种:结构化数据和非结构化数据. 结构化数据:指具有固定格式或有限长度的数据,如数据库,元数据等. 非结构化数据:指不定长或无固定格式 ...
- MATLAB添加工具箱及无法连接到MathWorks问题
版本信息:官网下载的MATLAB R2019b 学生版 操作系统:Windows 10 在安装MATLAB时,需要我们自行选择要安装工具箱,如何在已安装MATLAB后添加当初没有选择安装的工具箱呢?第 ...
- eclipse创建java和web工程
JAVA Eclipse→File→New→Project.. WEB 右键mvn项目→Properties src/main/webapp pom.xml <project xmlns=&qu ...
- 学习jQuery基础语法,并通过一个案例引出jQuery的核心
jquery是一个快速.小巧,功能强大的javascript函数库. jquery主要用来替代原生的javascript,简化代码. 前端最头疼的就是兼容:IE6/7/8兼容的最高版本是jQuery1 ...
- hadoop3自学入门笔记(2)—— HDFS分布式搭建
一些介绍 Hadoop 2和Hadoop 3的端口区别 Hadoop 3 HDFS集群架构 我的集群规划 name ip role 61 192.168.3.61 namenode,datanode ...
- UI设计的定义和view、viewgroup及其一些常用属性
1.uI设计 UI设计就是用户界面设计,比如QQ登录界面.聊天界面等,进行UI设计将会用到View和Viewgroup. 2.view 在安卓中可以理解为视图,在安卓中占用一块矩形区域,负责提供主件绘 ...
- Enable VT-x in your BIOS security settings, ensure that HAXM is installed properly. Try disabling 3rd party security software if the problem still occurs
win7系统安装了了AndroidStudio3.5后用模拟器报错:Enable VT-x in your BIOS security settings, ensure that HAXM is in ...