hdu6152(拉姆齐(Ramsey)定理) Friend-Graph

2017年08月19日 10点热度 0人点赞 0条评论

Friend-Graph

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


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

1
4
1 1 0
0 0
1
 


Sample Output

Great Team!

以下代码是错的,但是水过了

#include
#include
#include
#include
#include
#include
#include
const int mn=3005;
using namespace std;
int f[mn],n;
inline int readint() {
	//只能读取非负int
	char c=getchar();
	while(!isdigit(c)) c=getchar();
	int x=0;
	while(isdigit(c)) {
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}
int find(int x) {
	if(x==f[x]) return x;
	int t=f[x];
	f[x]=find(f[x]);
	return f[x];
}
set pp;
int ft[mn];
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		for(int i=1; i<=n; ++i)
			f[i]=i;
		memset(ft,0,sizeof(ft));
		for(int i=1; i=3) {
				cnt=3;
				break;
			}
			if(pp.count(fx=find(i))==0) {
				if(++cnt>=3) {
					break;
				}
				pp.insert(fx);
			}
		}
		if(cnt>=3) puts("Bad Team!");
		else puts("Great Team!");
	}
	return 0;
}

正解

/*
在组合数学上,拉姆齐(Ramsey)定理是要解决以下的问题:要找这样一个最小的数n,使得n个人中必定有k个人相识或l个人互不相识。
拉姆齐定理的通俗表述:
6 个人中至少存在3人相互认识或者相互不认识。
该定理等价于证明这6个顶点的完全图的边,用红、蓝二色任意着色,必然至少存在一个红色边三角形,或蓝色边三角形。
注:这个定理以弗兰克·普伦普顿·拉姆齐命名,1930年他在论文On a Problem in Formal Logic[2](《形式逻辑上的一个问题》)证明了R(3,3)=6。
*/
#include
#include
using namespace std;
int T,n;
int main() {
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		
			int a[10][10]={0};
			for(int i=1; i=6)
				{
					puts("Bad Team!");
					continue;
				}
				int f=0;
				for(int i=1;i<=n;++i)
				for(int j=i+1;j<=n;++j)
				for(int k=j+1;k<=n;++k)
				if(a[i][j]&&a[i][k]&&a[j][k])
				{
					f=1;
					break;
				}
				if(f) puts("Bad Team!");
				else puts("Great Team!");
	}
	return 0;
}

未经允许不得转载!hdu6152(拉姆齐(Ramsey)定理) Friend-Graph

update

纸上得来终觉浅, 绝知此事须躬行。