HDU 6152 2017中国大学生程序设计大赛网络赛 1003

来源:互联网 发布:萤火虫之墓影评知乎 编辑:程序博客网 时间:2024/06/06 19:02

Friend-Graph

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 904    Accepted Submission(s): 471


Problem Description
It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn’t be any small groups in a good team.
In a team with n members,if there are three or more members are not friends with each other or there are three or more members who are friends with each other. The team meeting the above conditions can be called a bad team.Otherwise,the team is a good team.
A company is going to make an assessment of each team in this company. We have known the team with n members and all the friend relationship among these n individuals. Please judge whether it is a good team.
 

Input
The first line of the input gives the number of test cases T; T test cases follow.(T<=15)
The first line od each case should contain one integers n, representing the number of people of the team.(n3000)

Then there are n-1 rows. The ith row should contain n-i numbers, in which number aij represents the relationship between member i and member j+i. 0 means these two individuals are not friends. 1 means these two individuals are friends.
 

Output
Please output ”Great Team!” if this team is a good team, otherwise please output “Bad Team!”.
 

Sample Input
141 1 00 01
 

Sample Output
Great Team!
 题意:一个团队中,如果三个或者三个以上的成员相互认识,或者三个或三个以上的成员之间互相都不认识,那么这个团队就是一个不好的团队,否则就是一个好团队,判断团队的好与坏。
读这个题目的时候,想着用两个数组记录,若大于等于3的话就可以判断了,但是队友讲是环的问题,我没怎么接触过,所以听他讲过以后,就要放弃了,后来,再做的的时候,发现都是那么一回事,但是自己对专业术语可能有点恐惧,so,对术语还是要多加熟悉
比较专业一点的术语如下:

题意:判定一个无向图是否有三个点的团或者三个点的独立集。

题解:Ramsey theorem,n >= 6 直接输出 Bad 否则暴力。

#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){    int a[3007],b[3001];    int t,n,m;    scanf("%d",&t);    while(t--)    {        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        scanf("%d",&n);        for(int i=1; i<n; i++)        {            for(int j=i+1; j<=n; j++)            {                scanf("%d",&m);                if(m==1)                {                    a[i]++;                    a[j]++;                }                else                {                    b[i]++;                    b[j]++;                }            }        }        for(int i=1; i<=n; i++)        {            if(a[i]>=3||b[i]>=3)            {                printf("Bad Team!\n");                break;            }            else            {                printf("Great Team!\n");                break;            }        }    }    return 0;}

利用拉姆齐定理用起来好快,差不多只有0MS,现在明白了,定理和算法的重要性
对拉姆齐定理简单说一下吧,其实我也是一知半解,讲讲为什么n>=6的时候,直接是bad team吧!
因为当n>=6的时候,必定有一个三个或三个以上的成员互相认识,或者三个或三个以上的成员互相不认识

证明如下:首先,把这6个人设为A、B、C、D、E、F六个点。由A点可以引出AB、AC、AD、AE、AF五条线段。设:如果两个人认识,则设这两个人组成的线段为红色;如果两个人不认识,则设这两个人组成的线段为蓝色。

由抽屉原理可知:这五条线段中至少有三条是同色的。不妨设AB、AC、AD为红色。若BC或CD为红色,则结论显然成立。若BC和CD均为蓝色,则若BD为红色,则一定有三个人相互认识;若BD为蓝色,则一定有三个人互相不认识。

折叠
#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){    int a[3007],b[3001];    int t,n,m;    scanf("%d",&t);    while(t--)    {        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        scanf("%d",&n);        if(n>=6)        {            printf("Bad Team!\n");        }        else if(n<=2)        {            printf("Bad Team!\n");        }        else        {            for(int i=1; i<n; i++)            {                for(int j=i+1; j<=n; j++)                {                    scanf("%d",&m);                    if(m==1)                    {                        a[i]++;                        a[j]++;                    }                    else                    {                        b[i]++;                        b[j]++;                    }                }            }            for(int i=1; i<=n; i++)            {                if(a[i]>=3||b[i]>=3)                {                    printf("Bad Team!\n");                    break;                }                else                {                    printf("Great Team!\n");                    break;                }            }        }    }    return 0;}



阅读全文
0 0