zoukankan      html  css  js  c++  java
  • 1829 A Bug's Life

    A Bug's Life

    Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 9223    Accepted Submission(s): 2965


    Problem 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
     1 #include<stdio.h>
     2 #include<string.h>
     3 int f[3000];
     4 int dis[3000];
     5 
     6 int find(int x)
     7 {
     8     int t;
     9     if(f[x]==x)
    10     return x;
    11 
    12     t=find(f[x]);
    13     dis[x]=(dis[x]+dis[f[x]])%2;
    14     f[x]=t;
    15     return t;
    16 
    17 }
    18 
    19 int make(int x,int y)
    20 {
    21     int a=find(x);
    22     int b=find(y);
    23     if(a==b)
    24     {
    25         if(dis[x]==dis[y])
    26             return 1;
    27         return 0;
    28     }
    29 
    30     f[a]=b;
    31     dis[a]=(dis[x]+dis[y]+1)%2;
    32     return 0;
    33 
    34 }
    35 
    36 int main()
    37 {
    38     //freopen("in.txt","r",stdin);
    39     int t,count=1;
    40     int n,m;
    41     int i,a,b,flag;
    42     scanf("%d",&t);
    43     while(t--)
    44     {
    45         scanf("%d%d",&n,&m);
    46         memset(dis,0,sizeof(dis));
    47 
    48         for(i=1;i<=n;i++)
    49         f[i]=i;
    50 
    51         flag=0;
    52         for(i=0;i<m;i++)
    53         {
    54             scanf("%d%d",&a,&b);
    55             if(make(a,b))
    56             {
    57                 flag=1;
    58             }
    59         }
    60 
    61         printf("Scenario #%d:
    ",count++);
    62         if(flag)
    63         printf("Suspicious bugs found!
    ");
    64         else
    65         printf("No suspicious bugs found!
    ");
    66         printf("
    ");
    67     }
    68     return 0;
    69 }
    View Code
     
  • 相关阅读:
    mysql-8.0.16-winx64/Linux修改root用户密码
    MYSQL学习笔记/2019
    博客论坛系统数据库之表的设计
    MySql-8.0.16版本部分安装问题修正
    将博客搬至CSDN
    解决远程连不到CentOS7虚拟机或ifconfig中没有ens33
    Windows本地运行调试Spark或Hadoop程序失败:ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path
    CentOS7安装Git-2.22.1
    CentOS7安装SVN1.9.12
    Storm本地启动拓扑报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/storm/topology/IRichSpout
  • 原文地址:https://www.cnblogs.com/xuesen1995/p/4105839.html
Copyright © 2011-2022 走看看