POJ 2492 A Bug's Life(并查集的变形)

A Bug's Life ACM简单并查集 优快云博客 问题描述 A Bug’s Life 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 ... 阅读详情

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 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
The first line of the input contains the number of scenarios. Each 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
The output for every scenario is a line containing “Scenario #i:”, 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

2
3 3
1 2
2 3
1 3
4 2
1 2
3 4

Sample Output

Scenario #1:
Suspicious bugs found!

Scenario #2:
No suspicious bugs found!

Hint

Huge input,scanf is recommended.

题意描述:
给出一个t代表有t组样例,然后再给出一个n和m,n代表的是有n个昆虫,昆虫标号为(1~n),然后再给出m行每行有两个标号代表这两个昆虫可以进行交配,问是否有同性恋的出现。

#include<stdio.h>

int n,f[2100],x[2100],flag;

void inti()
{
	for(int i=1;i<=n;i++)
	{
		f[i]=i;
		x[i]=1;//性别标记初始化
	}
	return ;
}

int getf(int i)
{
	if(f[i]==i)
		return i;
		
	int tmp=f[i];//保留所查到的祖先的子代。
	f[i]=getf(tmp);
	x[i]=(x[i]+x[tmp]+1)%2;//从新判定i的性别
	return f[i];	
}

void merge(int a,int b)
{
	int t1,t2;
	t1=getf(a);
	t2=getf(b);
	if(t1!=t2)
	{
		//printf("%d**%d*\n",t1,t2);
		f[t2]=t1;
		x[t2]=(x[a]+x[b])%2;//从新判定t2的性别
	}
	else
	{
		if((x[a]+x[b])%2==0)//0与0或者是1与1的情况
			flag=1;//标记是否有同性恋
	}
}

int main(void)
{
	int a,b,m,t,t1=1;

	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		flag=0;	
		inti();
		while(m--)
		{ 
			scanf("%d%d",&a,&b);
			merge(a,b);
		}
//		for(int i=1;i<=n;i++)
//			printf("%d ",x[i]);
		printf("Scenario #%d:\n",t1++);
		if(flag==1)
			printf("Suspicious bugs found!\n");
		else
			printf("No suspicious bugs found!\n");
		printf("\n");
	}
	return 0;
	
}


文档多模态识别工具对比:MinerU、PaddleOCR、Marker 本文对比了三款文档多模态识别工具:MinerU、PaddleOCR和Marker。MinerU专注于中文文档的端到端解析,支持复杂元素提取和结构化输出,适合中文论文和教材解析。PaddleOCR是通用OCR工具包,支持多语言和全流程任务,适用于发票、车牌等图像OCR。Marker则注重多语言支持和轻量化部署,适合英文论文和技术文档的快速转换。三者在核心技术、中文优化、表格处理、输出格式、部署复杂度和适用语言等方面各有优劣。选型建议根据具体需求:MinerU适合高精度中文解析,PaddleOCR适合定制化OC 阅读详情

相关推荐

NCBI|叶绿体基因组数据上传

叶绿体基因组NCBI上传 小编最近在NCBI上传了好几次数据…想着可以把具体的上传步骤写下来,供大家参考。以下是叶绿体基因组的上传示例,大家可以瞅瞅 图片 准备工作 1.登录NCBI官网:https://www.ncbi.nlm.nih.gov/, 依次点击“sign in to NCBI”——“See more 3rd party sign in options”——搜索“Microsoft live.com”。 ”sign in to NCBI“ ”See more 3rd party sign i

weifanbio的博客 3901

题解A Bug‘s Life(种类合并)

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 and their interac.

yaozizhi_yang的博客 666

Android系统开发工程师面试指南与参考答案

本文整理了Android系统开发工程师面试常见问题与参考答案。核心内容涵盖:1)Framework层定制方法,如修改HAL和系统服务;2)ANR问题分析工具(systrace)与解决方案;3)性能优化实践,包括开机加速和功耗管理;4)四大组件工作机制与应用案例;5)Native崩溃调试技巧。文章强调通过AOSP源码研究、工具使用和项目案例准备来提升面试表现,重点考察应聘者的系统开发深度和实操能力。参考答案均基于实际开发经验,提供可量化的优化成果说明。

郑伟强dev的专栏 256

A Bug‘s Life(带权并查集)

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.大概意思是:专家正在研究稀有品种,分为两种不同的性别,专家通过一些方法研究这些生物是同性恋还是异性恋。注:每组数据后有一空行。

coisini_dd的博客 240

厉害了,华为推出下一代光传送网:fgOTN

2024年10月,在全球信息技术博览会(GITEX Global 2024)上,华为正式发布了其颠覆性的创新产品——端到端细粒度光传送网(fgOTN)解决方案。这一产品组合被誉为行业内首个fgOTN,旨在重塑光传送网络的格局,满足电力运输等行业日益增长的通信需求。在过去的近三十年中,同步数字体系(SDH)技术一直是电信和工业网络的支柱,因其可靠性、稳定性和低延迟而备受青睐。然而,随着数据需求的激增,SDH的最大带宽仅为10 Gbps,逐渐显露出局限性。

网络技术联盟站 636

Autosar入门_OS_5

os hook函数说明

u012406840的博客 398

A Bug's Life

sex保存异性,(a,b)    同性的在一个集合,a一定和sex[b]是同性的,b一定和sex[a]是同性的。 Problem Description Background  Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that

步步为营 727

AI幻觉缓解的成本效益分析:投入产出比优化

在当今AI技术飞速发展的时代,AI幻觉成为了一个不容忽视的问题。AI幻觉就像是AI在“做梦”,会给出一些不符合实际或者错误的答案。我们这篇文章的目的就是要分析缓解AI幻觉所需要投入的成本和能够获得的效益,看看怎么能让投入和产出的比例达到最优。范围涵盖了常见的AI应用场景,比如智能客服、自动驾驶等领域。接下来,我们会先介绍一些和AI幻觉、成本效益分析相关的术语。然后用一个有趣的故事引出核心概念,解释什么是AI幻觉、成本效益分析等,以及它们之间的关系。

AI 原生应用开发的博客 935

POJ2492(种类并查集)

题目链接:

追梦赤子心 2941

指纹浏览器降维打击(下):Cloudflare Turnstile 与 hCaptcha 的底层交互逻辑

本文将深度拆解:Turnstile 与 hCaptcha 的 Iframe 沙箱通信机制,动态混淆 JS 与 PoW(工作量证明)的物理破解法则,以及如何通过 C++ 底层事件合成与环境基因强绑定,实现验证码的“无感过验”。

数据知道的博客 422

精通 Android NDK/JNI:从入门到精通实战与面试精粹

在Android开发中,

郑伟强dev的专栏 144

poj2492--A Bug's Life(并查集变形)

A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 28703   Accepted: 9350 Description Background  Professor Hopper is researching the sexual behavi

随风的专栏 1766

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

POJ P2492 A Bug's Life

A Bug's Life 又是一道坑爹的英文题。。。题目好难翻译啊!!!为减轻大家翻译负担,特地把题目大意叙述如下: 有个教授在搞虫子是否为同性恋的实验。。。(有点怪怪的感觉。。。)通过实验的一些结果,判断教授的观点是否正确,也就是判断实验的虫子中是否存在同性恋的虫子! 输入:第一个数输入实验的次数。接下来一行输入实验的虫子数n和研究的虫子对数m。接下来m行分别输入交配的

枫叶寻寻 714

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

POJ-2492-A Bug's Life(并查集)

                                                         A Bug's Life   Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they fea...

1228

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

(并查集)A Bug's Life -- POJ -- 2492

链接: 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> #incl...

weixin_33862041的博客 106

poj 2492A Bug's Life(并查集)

1 /* 2 目大意:输入一个数t,表示测试组数。然后每组第一行两个数字n,m,n表示有n只昆虫,编号从1—n,m表示下面要输入m行交配情况,每行两个整数,表示这两个编号的昆虫为异性,要交配。 3 要求统计交配过程中是否出现冲突,即是否有两个同性的昆虫发生交配。 4 5 思路:并查集 6 将同性的昆虫放入集合之中,如果输入的昆虫u, v同时出现在了集合中,那么 u...

weixin_33904756的博客 80

POJ-2492(看看有没有同性恋)(A bug's life)

【题目描述】 给出几对虫子交配,问是否有同性恋。 【解题思路】 并查集变形,把每条虫的所有对象合并 int p[10001]; int rank[10001]; int other[10001];/* 每个虫的对象 */ void make_set(int x) { p[x] = x; rank[x] = 0; other[x] = -1;/* 初始化每个虫的对象 */ } int

famousDT的专栏 684

poj分类解题报告索引

图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Journey poj1724 - ROADS(邻接表+DFS) BFS poj3278 - Catch That Cow(空间BFS) poj2251 - Dungeon Master

贰圣 9789

poj2492--A Bug's Life(并查集变形)

A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 28703   Accepted: 9350 Description Background  Professor Hopper is researching the sexual be...

weixin_33722405的博客 170

并查集

并查集          并查集是一种数据结构,一般它处理的是图(其实是解决无向图的)的连通分量问题,但是当并查集的根节点可以维护更多的信息时,并查集可以解决范围更广的基于无向图连通分量的问题。做了这么多并查集的题目后,我感觉并查集就是解决有关物与物之间的关系问题的数据结构且这种关系还必须是可传递的关系,所以一般遇到这种问题可以先尝试用并查集解决。          并查集的基

code 2754

POJ 2492 (并查集)

A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 20235   Accepted: 6578 Description Background Professor Hopper is researching the sexual behavi

Canon of Code 502

18.9.17 poj2492 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 opposi...

dhc65376的博客 196

B - 简单带权并查集 POJ - 2492 A Bug's Life

POJ - 2492http://poj.org/problem?id=2492 BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they ...

weixin_33973609的博客 163

带权并查集 hdu1829

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 gend...

qq_40620465的博客 231

(POJ2492)A Bug's Life <并查集判断是否同类>

A Bug’s Life DescriptionBackground 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

STILLxjy 633
上一篇: HDU 1071 The area(求面积)
下一篇: POJ 2236 Wireless Network(并查集)
鳳九~
博客等级 码龄8年 1384粉丝 215原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值