HDU Friend-Graph(离散数学)

来源:互联网 发布:淘宝客联盟如意投 编辑:程序博客网 时间:2024/06/03 05:46

Friend-Graph

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

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.(n≤3000)

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!
题意:给出n个人关系,问是否存在三个或者三个以上相互认识或者相互不认识。
题解:根据定理任意6个人之间,指定会出现三个人相互认识或者相互不认识。所以n>=6直接pass,剩下暴力判断即可。
代码:

#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<vector>#include<queue>#include<set>#include<algorithm>#include<map>#include<math.h>using namespace std;typedef long long int ll;typedef pair<int,int>pa;const int N=1e5+100;const int mod=1e9+7;const ll INF=1e18;int read(){    int x=0;    char ch = getchar();    while('0'>ch||ch>'9')ch=getchar();    while('0'<=ch&&ch<='9')    {        x=(x<<3)+(x<<1)+ch-'0';        ch=getchar();    }    return x;}/***********************************************************/int t,n,op;int mp[10][10];bool flag;int main(){    scanf("%d",&t);    while(t--)    {         memset(mp,0,sizeof(mp));        scanf("%d",&n);        for(int i=1;i<n;i++)        {            for(int j=1;j<=n-i;j++)            {                scanf("%d",&op);                if(n>=6||n<=2) continue;                if(op&1)                {                    mp[i][i+j]=1;                    mp[j+i][i]=1;                }            }        }        flag=false;        if(n>=6) puts("Bad Team!");        else if(n<=2)puts("Great Team!");        else        {            for(int i=1;i<=n;i++)            {                for(int j=i+1;j<=n;j++)                {                    for(int k=j+1;k<=n;k++)                    {                        if(mp[i][j]==mp[j][k]&&mp[j][k]==mp[i][k])                        {                            flag=true;                        }                        if(flag) break;                    }                    if(flag) break;                }                if(flag) break;            }            if(flag) puts("Bad Team!");            else puts("Great Team!");        }    }    return 0;}
原创粉丝点击