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!
此题是参赛队伍中提交人数最多也是AC人数最多的一道题。
这道题的大体意思是,在一个团队中有三个或以上的人认识(1)或者不认识(0)就是一个Bad Team,否则这个队伍是Great Team
第一行输入一个测试的数据组数,第二行输入有团队人数n,剩下的n-1行每行都是n-i个数字代表成员i和j之间的关系。
我们团队解决这道题的思路就是,一个3000*3000的邻接矩阵储存团队的关系,并且关系之间有像是一个有向图,1和2认识,那么肯定是2和1也认识。
所以这样,我们就可以只管一个矩阵中的一半。
随后依次记录下每一行关系1和0的个数,每一行1和0的关系有其中一个是大于等于3的,那么就说这不是一个好的团队。
同时要注意一点:使用cin会出现超时的现象,在大的数据或数据多的时候尽可能选择scanf。
代码如下:
#include<stdio.h>
int a[3001][3001];
int main()
{
int t;
int n,count1=0,count2=0;
scanf("%d",&t);
int flag=0;
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n-1;i++)
for(int j=i+1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
for(int i=1;i<=n-1;i++){
for(int j=i+1;j<=n;j++)
{
if(a[i][j]==1)
count1++;
if(a[i][j]==0)
count2++;
if(count1>=3||count2>=3){
flag=1;
count1=0;
count2=0;
}
}
count1=0;
count2=0;
}
if(flag)
printf("Bad Team!\n");
else
printf("Great Team!\n");
flag=0;
}
return 0;
}