您的位置:首页 > 理论基础 > 计算机网络

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

2017-08-19 20:35 721 查看


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.(n≤3000)

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!

 

Source

2017中国大学生程序设计竞赛
- 网络选拔赛

#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

;
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条边中任何一条都不是红色,它们必然是蓝色,因此,它们组成了一个蓝色三角形。

红色-有边
蓝色-无边

于是得证。

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐