poj 2492 A BUG'S LIFE 不是纯裸的并查集

本文深入探讨了人工智能算法在IT领域的应用,包括开发工具、大数据开发、嵌入式开发环境、音视频基础等细分技术领域。文章详细介绍了各领域内的关键技术、工具和实践案例,旨在帮助开发者更全面地理解并应用这些技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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. 
题意:就是给你一个一群编号从1-n的虫子,然后给出一些关系表示相互间是不同性别,让你判断有没有矛盾,有矛盾就输出Suspicious bugs found!,没有就输出No suspicious bugs found!举个例子吧:第一个案列就是说有三只虫子,给出了三种关系,1和2 是不同性别,2和3是不同性别,我们可以知道1和3是相同性别,但给出的是1和3是不同性别产生了矛盾就有bugl输出就好了,第二个案例就是说1,2是不同性别,3,4是不同性别显示没有矛盾。
思路:我们需要两个数组,一个用来存放虫子所属的分组,一个用来存虫子的性别,首先我们假定每个虫子都在不同的分组,每个虫子与自己都是同性用0表示,当异性在一起的时候,把他们放在同一个集合里面,其中一个变为性别1,然后在最后判断的时候看看给定的两个虫子在不在同一个分组里面,在同一个分组里 如果两个的性别相同的话那就是有矛盾了。

做的太单纯,错了好多次,后来想清楚了还是错,给自己一组测试数据没过3 3 1 2 1 2 1 2 答案 No suspicious bugs found!结果就是不对啊,后来才意识到就是需要标记每个虫子的性别,然而并不懂怎么做,看了博客,就知道了怎样来做。

总结:做题想的深一点,不要太简单的去做它,这道题收获了不少。

AC代码:
#include <iostream>
#include <cstdio>
using namespace std;
int fu[2010];//他的父亲的状态
int zi[2010];//自己的状态
int found(int x){//找当前孩子的父亲
    int r ;
    if(x == fu[x]){
        return x;
    }
        r = fu[x] ;
        fu[x] = found(fu[x]);
        zi[x] = (zi[x] + zi[r] ) % 2;//孩子的父亲改变了,就要更新孩子的性别
    return fu[r];
}
void bing(int x,int y){
    int xx = found (x);
    int yy = found (y);
    fu[yy] = xx;
    zi[yy] = (zi[x] - zi[y] + 1) % 2;//合并两个虫子,在同一个分组,标记两个孩子性别不同
}
int main(){
    int t;
    int bug;
    int guanxi;
    scanf("%d",&t);
    for(int j = 1;j <= t ;j++){
        scanf("%d%d",&bug,&guanxi);
        for(int i = 1; i <= bug; ++i){
            fu[i] = i;
            zi[i] = 0;
        }
        int flag = 0;
        int bug1,bug2;
        while(guanxi--){
            scanf("%d%d",&bug1,&bug2);
                if(found ( bug1 ) == found (bug2)){
                    if(zi[bug1] == zi[bug2]){
                        flag = 1;
                    }
                }
                else{
                    bing(bug1,bug2);
                }
        }
        printf("Scenario #%d:\n",j);
        if(flag == 0){
            printf("No suspicious bugs found!\n\n");
        }
        else{
            printf("Suspicious bugs found!\n\n");
        }
    }
    return 0;
}

附 组测试数据
3 3
1 2
1 2
1 2
很重要的
         
 
内容概要:本文档为《400_IB Specification Vol 2-Release-2.0-Final-2025-07-31.pdf》,主要描述了InfiniBand架构2.0版本的物理层规范。文档详细规定了链路初始化、配置与训练流程,包括但不限于传输序列(TS1、TS2、TS3)、链路去偏斜、波特率、前向纠错(FEC)支持、链路速度协商及扩展速度选项等。此外,还介绍了链路状态机的不同状态(如禁用、轮询、配置等),以及各状态下应遵循的规则和命令。针对不同数据速率(从SDR到XDR)的链路格式化规则也有详细说明,确保数据包格式和控制符号在多条物理通道上的一致性和正确性。文档还涵盖了链路性能监控和错误检测机制。 适用人群:适用于从事网络硬件设计、开发及维护的技术人员,尤其是那些需要深入了解InfiniBand物理层细节的专业人士。 使用场景及目标:① 设计和实现支持多种数据速率和编码方式的InfiniBand设备;② 开发链路初始化和训练算法,确保链路两端设备能够正确配置并优化通信质量;③ 实现链路性能监控和错误检测,提高系统的可靠性和稳定性。 其他说明:本文档属于InfiniBand贸易协会所有,为专有信息,仅供内部参考和技术交流使用。文档内容详尽,对于理解和实施InfiniBand接口具有重要指导意义。读者应结合相关背景资料进行学习,以确保正确理解和应用规范中的各项技术要求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值