HDU-6125-Friend-Graph-2017CCPC网络赛(图论,拉姆齐定理-组合数学)
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网络赛(图论,拉姆齐定理-组合数学)的更多相关文章
- HDU 4764 Stone (2013长春网络赛,水博弈)
Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU - 6156 2017CCPC网络赛 Palindrome Function(数位dp找回文串)
Palindrome Function As we all know,a palindrome number is the number which reads the same backward a ...
- HDU 6212 Zuma 2017青岛网络赛 区间DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6212 解法:看了眼题就发现这个BZOJ 1032不是一毛一样?但是BZOJ上那是个巨坑,数据有错,原来 ...
- hdu 4751 2013南京赛区网络赛 二分图判断 **
和以前做过的一个二分图颇为相似,以前的是互相不认识的放在一组,这个是互相认识的,本质上是相同的 是 hdu 2444 #include<cstdio> #include<iostre ...
- hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...
- hdu 4035 2011成都赛区网络赛E 概率dp ****
太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...
- HDU 5044(2014 ACM-ICPC上海网络赛)
题意:给定一个树形图,节点10^5,有两种操作,一种是把某两点间路径(路径必定唯一)上所有点的权值增加一个固定值. 另一种也是相同操作,不同的是给边加权值.操作次数10^5.求操作过后,每个点和每条边 ...
- HDU 5839 Special Tetrahedron (2016CCPC网络赛08) (暴力+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...
- hdu 5438 Ponds(长春网络赛 拓扑+bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5438 Ponds Time Limit: 1500/1000 MS (Java/Others) ...
随机推荐
- for 续2
--------siwuxie095 (二)skip=n 忽略(屏蔽.隐藏)文本前 N 行的内容. (N 必须大于 0,不能等于 0) 格式: FOR /F " ...
- Centos 7.2编译安装MariaDB-10.0.xx
系统: centos7.2 x64数据库:MariaDB-10.0.30 使用jemalloc对MySQL内存进行优化. 软件包下载地址:http://pan.baidu.com/s/1eS44OKU ...
- Spring MVC的handlermapping之请求分发如何找到正确的Handler(BeanNameUrlHandlerMapping,SimpleUrlHandlerMapping)
本文讲的是Spring MVC如何找到正确的handler, 前面请求具体怎么进入到下面的方法,不再细说. 大概就是Spring mvc通过servlet拦截请求,实现doService方法,然后进入 ...
- SGU 194 Reactor Cooling (有容量和下界的可行流)
题意:给定上一个有容量和下界的网络,让你求出一组可行解. 析:先建立一个超级源点 s 和汇点 t ,然后在输入时记录到每个结点的下界的和,建边的时候就建立c - b的最后再建立 s 和 t , 在建立 ...
- 第二届CCCC赛后感想 2017-04-15 23:56 88人阅读 评论(0) 收藏
第一次写赛后感想,也不算什么很正规的比赛,不过这次比赛的时间恰好处于思想变化的阶段,留贴纪念. 先谈谈这次比赛,弱校萌新,依靠申请进了总决赛,发现和第一届不一样,缺少了团队奖心中有点缺乏动力,比赛2个 ...
- Android-sdcard广播的接收处理
有时候Android手机在开机成功后的那几秒会在状态栏通知,Sdcard开始扫描,Sdcard扫描完成,等信息 当Sdcard的状态发生改变后,系统会自动的发出广播 Sdcard的状态: 1.moun ...
- 前端与HTTP
本文整理在,我的github 上.欢迎Star. 各版本的http 发展 在HTTP建立之初,主要是为了传输超文本标记语言(HTML)文档.随着时代的发展,也进行了若干次演进.下图是各个版本发布的时间 ...
- chrome一个奇怪的问题
我去........... 这牢骚发完了才发现, 多谢了个e 呃................. ================================= 晚上用bootstrap搭建一 ...
- 在定制工作项时,把“团队项目”作为变量获取生成版本信息
有用户最近提出这个需求: 通过工作项定制,新增一个字段用以保存项目Bug的"影响版本"信息,但是需要从当前团队项目的服务器生成纪录中获取版本的选项,类似默认模板中的"发现 ...
- 3:C#异步WaitAll的使用
编写界面如图: private async void button1_Click(object sender, EventArgs e) { #region 单个执行的异步,效率慢 HttpClien ...