麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發(fā)設計 > 正文

A Bug's Life

2019-11-10 19:42:34
字體:
供稿:網(wǎng)友

A Bug's Life

時間限制:1000 ms  |  內(nèi)存限制:65535 KB難度:4描述 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.輸入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 10000) 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.輸出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.樣例輸入
23 31 22 31 34 21 23 4樣例輸出
Scenario #1:Suspicious bugs found!Scenario #2:No suspicious bugs found!

解題報告:種類并查集。把性別相同的蟲子放在同一個集合,然后每讀入一對蟲子號,判斷它們在不在同一集合,在則同性別,不在則繼續(xù)。

code

#include<iostream>#include<stdio.h>#include<queue>#include<vector>#include<stack>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const int MAXN = 10005; /*結點數(shù)目上限*/int pa[MAXN];    /*pa[x]表示x的父節(jié)點*/int rank[MAXN];    /*rank[x]是x的高度的一個上界*/int gender[MAXN];  // 與i性別相反的蟲子號/*創(chuàng)建一個單元集*/void make_set(int x){    pa[x] = x;    rank[x] = 0;    gender[x]=0;}/*帶路徑壓縮的查找*/int find_set(int x){    if(x != pa[x]){        pa[x] = find_set(pa[x]);    }    return pa[x];}/*按秩合并x,y所在的集合*/void union_set(int x, int y){    x = find_set(x);    y = find_set(y);    if(rank[x] > rank[y])/*讓rank比較高的作為父結點*/    {        pa[y] = x;    }    else    {        pa[x] = y;        if(rank[x] == rank[y])            rank[y]++;    }}int main(){  //  freopen("input.txt","r",stdin);    int t,m,n,k=1;    scanf("%d",&t);    while(t--){        scanf("%d%d",&m,&n);        for(int i=1;i<=m;i++){ //初始化            make_set(i);        }        int a,b,flag=1;        for(int i=0;i<n;i++){            scanf("%d%d",&a,&b);            if(!flag) //結果出來之后也要把數(shù)據(jù)讀完                continue;            if(find_set(a)==find_set(b)){  //判斷兩個蟲子在不在同一個集合                flag=0;                continue;            }            if(gender[a]==0) gender[a]=b; //把性別相同的蟲子放在同一個集合里            else union_set(gender[a],b);            if(gender[b]==0) gender[b]=a;            else union_set(gender[b],a);        }        if(k!=1)            printf("/n");        if(flag)            printf("Scenario #%d:/nNo suspicious bugs found!/n",k++);        else            printf("Scenario #%d:/nSuspicious bugs found!/n",k++);    }    return 0;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 久久精品高清 | 国产免费视频一区二区裸体 | 31freehdxxxx欧美 | 中文字幕国产一区 | 黄色免费av | 91,视频免费看| 成人综合区一区 | 龙的两根好大拔不出去h | 色日本视频 | 日韩精品久久久久久 | 久久久久久久久久久国产精品 | 一区二区三区视频在线观看 | 久久久精品视频免费看 | 国产无限资源在线观看 | 日本在线一区二区 | 一本色道久久综合亚洲精品图片 | 羞羞漫画无遮挡观看 | 成人在线视频一区 | 亚洲成人夜色 | 中文字幕激情视频 | 九一国产精品 | 成人在线视频一区 | 黄色大片高清 | 色诱亚洲精品久久久久久 | 色婷婷tv | 欧美一级淫片免费视频黄 | 热99精品视频 | 中国免费一级毛片 | 2019中文字幕在线播放 | 亚洲欧美国产高清 | 欧美成人二区 | 成人在线视频免费播放 | 欧美一级成人 | 一级电影在线免费观看 | 日本残忍极度灌浣肠视频 | 91av国产在线 | 久久久久久久久久久久久国产精品 | 欧洲成人精品 | 69av导航| 国产精品一区二区三区99 | 狠狠干五月天 |