Friend-Graph(图的暴力)

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.()

Then there are n-1 rows. The th row should contain n-i numbers, in which number  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!

题意:t组输入,每组n个人,给你这n个人之间的关系,如果三个人互为朋友或者三个人都不是朋友,则这个队伍是Bad Team!,否则是Great Team!。

思路:用图来表示一个队伍n个人之间的关系,用数组来存储这个图,注意输入的数据是第i个人和第i+j个人的关系,数组用布尔型数组来存储。

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstdlib>
using namespace std;
bool x[3010][3010];//bool型数组
int main()
{
	int t,n,a;
	cin>>t;
	while(t--)
    {
    	int flag=0;
    	cin>>n;
    	for(int i=1;i<n;i++)
    		for(int j=1;j<=n-i;j++)
    		{
    			cin>>a;
    			x[i][j+i]=a;
    			x[j+i][i]=a;
    		}
    	for(int i=1;i<=n;i++)  //暴力图
    	{
    		for(int j=i+1;j<=n;j++)
    		{
    			for(int k=j+1;k<=n;k++)
    			{
    				if(x[i][j]==x[j][k]&&x[j][k]==x[k][i])  //三个人关系相同
    				{
    					flag=1;
    					break;
    				}
    			}
    			if(flag)  break;
    		}
    		if(flag)  break;
    	}
    	if(flag)  cout<<"Bad Team!"<<endl;
    	else      cout<<"Great Team!"<<endl;
    }
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42279796/article/details/81019290