HDU 6152 Friend-Graph

来源:互联网 发布:投资公司的网络销售 编辑:程序博客网 时间:2024/06/08 03:57

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

141 1 00 01

Source

2017中国大学生程序设计竞赛 - 网络选拔赛

Sample Output

Great Team!

题目大意

有一个表示朋友关系的无向图,如果有三个或超过三个的人彼此之间都不是朋友,或者有三个或超过三个以上的朋友彼此之间都是朋友,那么这是一个Bad Team,否则是Great Team!

解题思路

当成员人数超过6时一定是Bad Team,因为此时如果成员仅仅两两之间都是朋友则一定会有三个人之间没有联系,但是再多加一条线便会形成三人成环;其余情况单独判断即可。

代码实现

#include <iostream>#include<cstdio>#include<cstring>using namespace std;#define maxn 3007int countt[maxn];int main(){    int T,n,t;    int maxx,minn;    scanf("%d",&T);    while(T--)    {        maxx=0,minn=maxn;        memset(countt,0,sizeof(countt));        scanf("%d",&n);        for(int i=1;i<n;i++)        {            for(int j=i+1;j<=n;j++)            {                scanf("%d",&t);                if(t==1)                {                    countt[i]++,countt[j]++;                    maxx=max(maxx,countt[i]); //标记顶点最大度                    maxx=max(maxx,countt[j]);                  }            }        }        for(int i=1;i<=n;i++)            minn=min(minn,countt[i]);  //标记顶点最小度        if(n>=6)            printf("Bad Team!\n");        else if(n<=2)            printf("Great Team!\n");        else if(n==3)        {            if(minn==maxx&&(maxx=0||maxx==2))                printf("Bad Team!\n");            else                printf("Great Team!\n");        }        else        {            if(maxx<3&&minn>=n-3)                printf("Great Team!\n");            else                printf("Bad Team!\n");        }    }    return 0;}
原创粉丝点击