poj 2492(并查集的带权向量关系)

本文解析了一个名为ABug'sLife的编程竞赛题目,该题要求根据虫子间的交互判断是否存在同性恋行为,挑战选手的数据结构和算法能力。通过使用并查集算法解决此问题,代码中详细展示了如何实现并查集以及判断逻辑。
A Bug's Life
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 28395 Accepted: 9256

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

Source

TUD Programming Contest 2005, Darmstadt, Germany

关于带权向量的问题在poj 1182那篇里有详细的解释,不懂的先去我的博客分类 并查集里找出来看看这类题目就都会做了,这里就不再赘述。

AC代码:

#include<iostream>
#include<stdio.h>
using namespace std;
int f[2010],rank[2010];
int find(int x){
    if(x==f[x])
        return x;
    int tf=f[x];
    f[x]=find(f[x]);
    rank[x]=(rank[x]+rank[tf])%2;
    return f[x];
}
int main(){
    int T; scanf("%d",&T);
    for(int cas=1;cas<=T;cas++){
        int n,m;
        int sucess=0;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            f[i]=i;
            rank[i]=0;       //0表示i的父节点与自己同性,1为异性
        }
        while(m--){
            int x,y;
            scanf("%d%d",&x,&y);
            int fx=find(x);
            int fy=find(y);
            if(fx!=fy){
                f[fx]=fy;
                rank[fx]=(1+rank[y]-rank[x]+2)%2;
            }
            else{
                if(rank[x]==rank[y]){
                    sucess=1;         //出现同性
                    while(m--){
                        scanf("%d%d",&x,&y);
                    }
                    break;
                }
            }
        }
        cout<<"Scenario #"<<cas<<":"<<endl;
        if(sucess==1){
            cout<<"Suspicious bugs found!"<<endl<<endl;
        }
        else
            cout<<"No suspicious bugs found!"<<endl<<endl;
    }
    return 0;
}



【电能质量扰动】基于ML和DWT的电能质量扰动分类方法研究(Matlab实现)内容概要:本文研究了一种基于机器学习(ML)和离散小波变换(DWT)的电能质量扰动分类方法,并提供了Matlab实现方案。首先利用DWT对电能质量信号进行多尺度分解,提取信号的时频域特征,有效捕捉电压暂降、暂升、中断、谐波、闪变等常见扰动的关键信息;随后结合机器学习分类器(如SVM、BP神经网络等)对提取的特征进行训练分类,实现对不同类型扰动的自动识别准确区分。该方法充分发挥DWT在信号去噪特征提取方面的优势,结合ML强大的模式识别能力,提升了分类精度鲁棒性,具有较强的实用价值。; 适合人群:电气工程、自动化、电力系统及其自动化等相关专业的研究生、科研人员及从事电能质量监测分析的工程技术人员;具备一定的信号处理基础和Matlab编程能力者更佳。; 使用场景及目标:①应用于智能电网中的电能质量在线监测系统,实现扰动类型的自动识别;②作为高校或科研机构在信号处理、模式识别、电力系统分析等课程的教学案例或科研实验平台;③目标是提高电能质量扰动分类的准确性效率,为后续的电能治理设备保护提供决策依据。; 阅读建议:建议读者结合Matlab代码深入理解DWT的实现过程特征提取步骤,重点关注小波基选择、分解层数设定及特征向量构造对分类性能的影响,并尝试对比不同机器学习模型的分类效果,以全面掌握该方法的核心技术要点。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值