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. mybatis逆向工程的注意事项:mapper文件内容不是覆盖而是追加

    XXXMapper.xml文件已经存在时,如果进行重新生成则mapper.xml文件内容不被覆盖而是进行内容追加,结果导致mybatis解析失败. 解决方法:删除原来已经生成的mapper xml文件 ...

  3. 关闭Found duplicated code

    IDEA中的这个“发现重复代码 - Found duplicated code“的这个提示甚是烦躁. Settings —> Editor —> Inspections —> Gen ...

  4. tp5主从数据库设置读写分离

    // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '192.168.0.5,192.168.0.6', // 数据库名 'databas ...

  5. SDWebImage从缓存中获取图片

      if ([[SDImageCache sharedImageCache] imageFromKey:sort.imageUrl]) {         [cell.photoImageView s ...

  6. 20169221 2016-2017-2《移动平台与android开发》学习总结

    每周作业连接汇总 第一周<Intellj IDEA 简易教程>学习,码云的基础使用.由于第一次写作业,网络攻防作业占据了我整个周四周五周六的时间这周java时间被挤没了,所以没有完成所有学 ...

  7. [Selenium With C#基础教程] Lesson-02 Web元素定位

    作者:Surpassme 来源:http://www.jianshu.com/p/cfd4ed1daabd 声明:本文为原创文章,如需转载请在文章页面明显位置给出原文链接,谢谢. 使用Selenium ...

  8. SQLSERVER带端口号的链接方式

    SQLSERVER带端口号的链接方式 <add key="BBAcnn" value="server=IP,端口号\实例名;database=TESTDB;uid= ...

  9. [Elixir001]使用tty做一个简单的日记记录

    大半年前实践的使用Evernote做知识管理 https://www.zhihu.com/question/20232993/answer/34270710里面的记录日记模块大概长成这样子 用了半年, ...

  10. sqlhelper写调用存储过程方法

    public static object Proc(string ProcName, SqlParameter[] parm) { conn.Open(); //最后一个参数为输出参数 parm[pa ...