Friend-Graph

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

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

1 1 0

0 0

Sample Output

Great Team!

题意:如果有三个及以上的人彼此认识或者三个及以上的人彼此不认识就是Bad Team!,否则就是Great Team!。正常思路就是建图暴力跑,然而3000*3000的矩阵会爆内存,瞎暴力很容易TLE。

拉姆齐定理

在组合数学上, 拉姆齐(Ramsey)定理是要解决以下的问题:要找这样一个最小的数n ,使得n个人中必定有k个人相识或l个人互不相识。

通俗表述

6 个人中至少存在3人相互认识或者相互不认识。

该定理等价于证明这6个顶点的完全图的边,用红、蓝二色任意着色,必然至少存在一个红色边三角形,或蓝色边三角形。

验证推导

R(3,3)=6

证明如下:首先,把这6个人设为A、B、C、D、E、F六个点。由A点可以引出AB、AC、AD、AE、AF五条线段。设:如果两个人认识,则设这两个人组成的线段为红色;如果两个人不认识,则设这两个人组成的线段为蓝色。

由抽屉原理可知:这五条线段中至少有三条是同色的。不妨设AB、AC、AD为红色。若BC或CD为红色,则结论显然成立。若BC和CD均为蓝色,则若BD为红色,则一定有三个人相互认识;若BD为蓝色,则一定有三个人互相不认识。

好了,现在再看这个题简直就水的不行了,正常建图要int类型3000*3000的矩阵会爆内存,暴力跑for循环还会TLE,现在根本都不存在了。

#include <bits/stdc++.h>
using namespace std; bool G[6][6]; int main()
{
int T;
scanf("%d", &T);
while( T-- )
{
int n;
scanf("%d", &n);
for( int i=1; i<=n; i++ )
{
for( int j = i + 1; j <= n; j++ )
{
int e;
scanf("%d", &e);
if( n <= 6 )
G[j][i] = G[i][j] = e;
}
} if(n < 3)
{
printf("Great Team!\n");
continue;
} if(n >= 6)
{
printf("Bad Team!\n");
continue;
} bool flag = false;
for( int a = 1; a <= n; a++ )
for( int b = a + 1; b <= n; b++ )
for( int c = b + 1; c <= n; c++ )
if( (G[a][b] && G[a][c] && G[b][c]) ||
(!G[a][b] && !G[a][c] && !G[b][c]) )
flag = true; if( flag ) printf("Bad Team!\n");
else printf("Great Team!\n");
}
return 0;
}

HDU-6125-Friend-Graph-2017CCPC网络赛(图论,拉姆齐定理-组合数学)的更多相关文章

  1. HDU 4764 Stone (2013长春网络赛,水博弈)

    Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. HDU - 6156 2017CCPC网络赛 Palindrome Function(数位dp找回文串)

    Palindrome Function As we all know,a palindrome number is the number which reads the same backward a ...

  3. HDU 6212 Zuma 2017青岛网络赛 区间DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6212 解法:看了眼题就发现这个BZOJ 1032不是一毛一样?但是BZOJ上那是个巨坑,数据有错,原来 ...

  4. hdu 4751 2013南京赛区网络赛 二分图判断 **

    和以前做过的一个二分图颇为相似,以前的是互相不认识的放在一组,这个是互相认识的,本质上是相同的 是 hdu 2444 #include<cstdio> #include<iostre ...

  5. hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***

    新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...

  6. hdu 4035 2011成都赛区网络赛E 概率dp ****

    太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...

  7. HDU 5044(2014 ACM-ICPC上海网络赛)

    题意:给定一个树形图,节点10^5,有两种操作,一种是把某两点间路径(路径必定唯一)上所有点的权值增加一个固定值. 另一种也是相同操作,不同的是给边加权值.操作次数10^5.求操作过后,每个点和每条边 ...

  8. HDU 5839 Special Tetrahedron (2016CCPC网络赛08) (暴力+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...

  9. hdu 5438 Ponds(长春网络赛 拓扑+bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5438 Ponds Time Limit: 1500/1000 MS (Java/Others)     ...

随机推荐

  1. 在Action中获取表单提交数据

    -----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2 ...

  2. 存储过程返回update结果集和insert主键

    update teacher set name ='111' where id in(286,289);print @@rowcount;--或select将查出,是@@rowcount,不是@row ...

  3. mysql启动参数 skip-grant-tables

    非常有用的mysql启动参数—— --skip-grant-tables. 顾名思义,就是在启动mysql时不启动grant-tables,授权表.有什么用呢?当然是忘记管理员密码后有用. 在mysq ...

  4. golang之包和锁的机制

    互斥锁 同一时刻只有一个携程在操作 package main import ( "fmt" "math/rand" "sync" " ...

  5. pyspider示例代码三:用PyQuery解析页面数据

    本系列文章主要记录和讲解pyspider的示例代码,希望能抛砖引玉.pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一些 ...

  6. C程序设计语言(2)文摘

    第一章 导言 1.1 入门 1.2 变量与算术表达式 1.3 for语句 1.4 符号常量 1.5 字符输入输出 #include "stdafx.h" main(int argc ...

  7. linux每天一小步---grep命令详解

    1 命令功能 grep(global regular expression print全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来. g ...

  8. Python + selenium + unittest装饰器 @classmethod

    前言 前面讲到unittest里面setUp可以在每次执行用例前执行,这样有效的减少了代码量,但是有个弊端,比如打开浏览器操作,每次执行用例时候都会重新打开,这样就会浪费很多时间. 于是就想是不是可以 ...

  9. Github 的注册教程和初步使用体验

    我叫许晴,是网工143的学生,学号是1413042064,兴趣包括手绘,看书和手游.学习过c++和汇编语言课程,但在编程方面没什么独立实践经验. 我的Githup用户名是 XQ123 .下面是我在gi ...

  10. Python2.4+ 与 Python3.0+ 主要变化与新增内容

    Python2                          Python3print是内置命令                 print变为函数print >> f,x,y     ...