hdu6152

来源:互联网 发布:淘宝联盟高佣金通过 编辑:程序博客网 时间:2024/06/10 16:16

Friend-Graph

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


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!
 

题意:有n个人,不能有3个人互不认识,也不能有三个人对于其他两人都认识,这样为好的团队,否则为坏的团队。

思路:其实就是找三元环,要找两种三元环,一是在认识关系中的三元环,二是在其补集中(即不认识网络)寻找三元环。要使得一个网络和它的补集都没有三元环,就要对于每个图都尽量多使用边,这样就要尽量制造四元环,那如果一个点和另一个点有连线那么就要隔一个点再与那个点有连线来避免三元环,但当点多了之后会出现有相隔的两个点都与原来那个点没有连线,所以当点多到一定数目的时候是不行的。当点数为5的时候可以制造五元环,当点数大于等于6的时候必然存在三元环。


#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int n;int map[10][10];int main(){int t;scanf("%d",&t);while(t--){memset(map,-1,sizeof(map));scanf("%d",&n);if(n>=6){int x;for(int i=0;i<n-1;i++){for(int j=i+1;j<n;j++)scanf("%d",&x);}printf("Bad Team!\n");continue;}else{int i;for(i=0;i<n-1;i++){for(int j=i+1;j<n;j++){scanf("%d",&map[i][j]);map[j][i]=map[i][j];}}for(i=0;i<n-1;i++){int j;for(j=i+1;j<n;j++){int flag=map[i][j];int k;for(k=0;k<n;k++){if(map[i][k]==flag&&map[j][k]==flag){//cout<<"asds  "<<i<<' '<<j<<' '<<k<<endl;break;}}if(k<n)break;}if(j<n)break;}if(i==n-1)printf("Great Team!\n");elseprintf("Bad Team!\n");}}}



原创粉丝点击