【HDU6152 2017中国大学生程序设计竞赛 - 网络选拔赛 C】【暴力 鸽巢原理】Friend-Graph

55 篇文章 0 订阅
1 篇文章 0 订阅

Friend-Graph

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


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  i th 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!
 

Source

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 3030, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n;
bool e[N][N];
bool Exist()
{
	if (n >= 6)return 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = i + 1; j <= n; ++j)
		{
			for (int k = j + 1; k <= n; ++k)
			{
				int sum = e[i][j] + e[j][k] + e[i][k];
				if (sum == 0 || sum == 3)return 1;
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d", &casenum);
	for (casei = 1; casei <= casenum; ++casei)
	{
		MS(e, 0);
		scanf("%d", &n);
		for (int i = 1; i <= n; ++i)
		{
			for (int j = i + 1; j <= n; ++j)
			{
				scanf("%d", &e[i][j]);
				e[j][i] = e[i][j];
			}
		}
		puts(Exist() ? "Bad Team!" : "Great Team!");
	}
	return 0;
}
/*
【trick&&吐槽】
鸽巢原理是证明的好方法!

【题意】
对于一个点数为n(3000)的图
让你求出其中是否存在 "一条边没有的三元对" 或者 "三条边的三元对"

【分析】
https://en.wikipedia.org/wiki/Ramsey%27s_theorem

在组合数学上,拉姆齐(Ramsey)定理,又称拉姆齐二染色定理,是要解决以下的问题:要找这样一个最小的数 n,使得 n 个人中必定有 k 个人互相认识或 k 个人互不相识。
这个定理以弗兰克·普伦普顿·拉姆齐命名,1930年他在论文On a Problem in Formal Logic(《形式逻辑上的一个问题》)证明了R(3,3)=6。

证明:在一个 n = 6的完全图内,每边涂上红或蓝色,必然有一个红色的三角形或蓝色的三角形。
任意选取一个端点P,它有5条边和其他端点相连。
根据鸽巢原理,5条边的颜色至少有3条相同,不失一般性设这种颜色是红色。
在这3条边除了 P以外的3个端点,它们互相连结的边有3条。
若这3条边中任何一条是红色,这条边的两个端点和 P相连的2边便组成一个红色三角形。
若这3条边中任何一条都不是红色,它们必然是蓝色,因此,它们组成了一个蓝色三角形。

红色-有边
蓝色-无边

于是得证。

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值