Friend-Graph(暴力枚举)

来源:互联网 发布:历史股价数据 编辑:程序博客网 时间:2024/06/05 19:16

Friend-Graph

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


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
141 1 00 01
 

Sample Output
Great Team!

题意:

给你一组人,如果一组人有三个人互相有关系或者有三个人和任何一个人都没关系,这就是一个bad team!给你数据让你判断。】

思路:

暴力枚举

代码:

#include <iostream>#include <cstring>#include <stdio.h>#include <algorithm>using namespace std;bool mp[3010][3010];bool finded(int n){int i,j,k;for(i=1;i<=n;i++)for(j=i+1;j<=n;j++)for(k=j+1;k<=n;k++){if(mp[i][j]==mp[i][k]&&mp[i][k]==mp[j][k]&&mp[i][j]==mp[j][k]) return 1;}return 0;}int main(){    int i,j;int n,m;cin>>n;int q;while(n--){cin>>m;for(i=1;i<m;i++){for(j=i+1;j<=m;j++){cin>>q;if(q==1)mp[j][i]=mp[i][j]=0;else mp[j][i]=mp[i][j]=1; }}bool flag=finded(m);if(!flag)cout<<"Great Team!"<<endl;else cout<<"Bad Team!"<<endl;}return 0;} 


原创粉丝点击