【组合数学--拉姆齐定理】hdu 6152 Friend-Graph

来源:互联网 发布:淘宝订单险 编辑:程序博客网 时间:2024/05/22 02:13

Friend-Graph

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

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
1
4
1 1 0
0 0
1
Sample Output 
Great Team!

题意:如果有三个或以上的人彼此认识或者彼此不认识输出Bad Team!;
思路:拉姆齐定理:6个人中至少有3个人互相认识或故乡不认识;
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define por(i,j,k) for(int i=j;i<=k;i++)#define nor(i,j,k) for(int i=j;i>=k;i--)#define clean(a,b) memset(a,0,sizeof(a))bool w[10][10];int n;bool solve(){    por(i,1,n)    por(j,i+1,n)    por(k,j+1,n)    {        if(w[i][j]==w[i][k]&&w[i][k]==w[j][k]&&w[j][k]==w[i][j])            return false;    }    return true;}int main(){    int t;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        if(n<6)        {            por(i,1,n-1)            por(j,i+1,n)            {                int x;                scanf("%d",&x);                if(x==1) w[i][j]=w[j][i]=true;                else  w[i][j]=w[j][i]=false;            }            if(solve())                printf("Great Team!\n");            else                printf("Bad Team!\n");        }        else        {            int x;            por(i,1,n-1)            por(j,i+1,n)            scanf("%d",&x);            printf("Bad Team!\n");        }    }    return 0;}



原创粉丝点击