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. Python编程快速上手(七)Unsplash批量下载器

    首发于个人博客:http://rhinoc.top/post/python_7.html 程序描述 V1.0输入关键字搜索图片,模拟页面下拉获取更多图片,页面加载完成后获取图片链接并下载至指定文件夹. ...

  2. MySql创建多表关联的步骤

    一,一对多表的创建 1.创建主表 create table HostTable( cid varchar(32) primary key, cname varchar(100)); 2.创建从表 cr ...

  3. Nuget安装 Identity组件。

    Install-Package Microsoft.AspNet.Identity.EntityFramework –Version 2.0.0(2.2.1) Install-Package Micr ...

  4. Linux文件备份

    1.tar -P是否保留根目录 -t查看压缩文件内容 -N 201401010备份日期以后 [root@localhost /]# tar -zcPf /tar/data2.tar.gz /etc/* ...

  5. RocketMQ 自定义文件路径

    一 .1. 修改store路径2. 修改logs路径3. 修改rmq_bk_gc.log路径4. 修改rmq_srv_gc.log路径二 .1. 获取正确的rocketmq 源码2. 地址:https ...

  6. swift 创建UICollectionView

    // //  CollectionViewController.swift //  tab // //  Created by su on 15/12/8. //  Copyright © 2015年 ...

  7. SQL SERVER 2012数据库:开启防火墙导致外部无法连接数据库解决办法

    SQL SERVER 2012数据库:开启防火墙导致外部无法连接数据库解决办法 将以下代码存为OpenSqlServerPort.bat文件: netsh advfirewall firewall a ...

  8. Synchronizer解析(为AQS打个铺垫)

    ReentranceLock 和 Semaphore有很多共同点,他们都像是一个gate一样, 来控制让哪些线程阻塞,让哪些线程通过. 不同的是,ReentranceLock允许通过的量是1,Sema ...

  9. 有關更新Java 至UPDATE 45 後出現沒法進入ORACLE EBS

    近日部份使用者在更新Java 至UPDATE 45 後出現沒法進入ORACLE.  解決方法如下. 在開始 => 程式集 => JAVA => Configure Java中 (Ja ...

  10. SEGGER J-Link install

    Why J-Link? In case you wonder why GNU ARM Eclipse decided to provide support to SEGGER J-Link, the ...