HDU 6152 2017中国大学生程序设计大赛网络赛 1003
来源:互联网 发布:萤火虫之墓影评知乎 编辑:程序博客网 时间:2024/06/06 19:02
Friend-Graph
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 904 Accepted Submission(s): 471
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.
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. Thei th 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.
The first line od each case should contain one integers n, representing the number of people of the team.(
Then there are n-1 rows. The
Output
Please output ”Great Team!” if this team is a good team, otherwise please output “Bad Team!”.
Sample Input
141 1 00 01
Sample Output
Great Team!
题意:一个团队中,如果三个或者三个以上的成员相互认识,或者三个或三个以上的成员之间互相都不认识,那么这个团队就是一个不好的团队,否则就是一个好团队,判断团队的好与坏。
读这个题目的时候,想着用两个数组记录,若大于等于3的话就可以判断了,但是队友讲是环的问题,我没怎么接触过,所以听他讲过以后,就要放弃了,后来,再做的的时候,发现都是那么一回事,但是自己对专业术语可能有点恐惧,so,对术语还是要多加熟悉
比较专业一点的术语如下:
题意:判定一个无向图是否有三个点的团或者三个点的独立集。
题解:Ramsey theorem,n >= 6 直接输出 Bad 否则暴力。
#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){ int a[3007],b[3001]; int t,n,m; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d",&n); for(int i=1; i<n; i++) { for(int j=i+1; j<=n; j++) { scanf("%d",&m); if(m==1) { a[i]++; a[j]++; } else { b[i]++; b[j]++; } } } for(int i=1; i<=n; i++) { if(a[i]>=3||b[i]>=3) { printf("Bad Team!\n"); break; } else { printf("Great Team!\n"); break; } } } return 0;}
利用拉姆齐定理用起来好快,差不多只有0MS,现在明白了,定理和算法的重要性
对拉姆齐定理简单说一下吧,其实我也是一知半解,讲讲为什么n>=6的时候,直接是bad team吧!
因为当n>=6的时候,必定有一个三个或三个以上的成员互相认识,或者三个或三个以上的成员互相不认识
证明如下:首先,把这6个人设为A、B、C、D、E、F六个点。由A点可以引出AB、AC、AD、AE、AF五条线段。设:如果两个人认识,则设这两个人组成的线段为红色;如果两个人不认识,则设这两个人组成的线段为蓝色。
由抽屉原理可知:这五条线段中至少有三条是同色的。不妨设AB、AC、AD为红色。若BC或CD为红色,则结论显然成立。若BC和CD均为蓝色,则若BD为红色,则一定有三个人相互认识;若BD为蓝色,则一定有三个人互相不认识。
折叠#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){ int a[3007],b[3001]; int t,n,m; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d",&n); if(n>=6) { printf("Bad Team!\n"); } else if(n<=2) { printf("Bad Team!\n"); } else { for(int i=1; i<n; i++) { for(int j=i+1; j<=n; j++) { scanf("%d",&m); if(m==1) { a[i]++; a[j]++; } else { b[i]++; b[j]++; } } } for(int i=1; i<=n; i++) { if(a[i]>=3||b[i]>=3) { printf("Bad Team!\n"); break; } else { printf("Great Team!\n"); break; } } } } return 0;}
阅读全文
0 0
- HDU 6152 2017中国大学生程序设计大赛网络赛 1003
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-1003-Friend-Graph
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-1001-Vertex Cover
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-1004-A Secret
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-1007-Palindrome Function
- 2016中国大学生程序设计竞赛-网络赛
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-1005-CaoHaha's staff
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-部分题解及代码
- 2017中国大学生程序设计竞赛(网络选拔赛) HDU 6154 CaoHaha's staff
- 2016中国大学生程序设计竞赛 - 网络选拔赛 hdu 5839 Special Tetrahedron
- Friend-Graph(中国大学生程序选拔赛2017年网络大赛)
- CaoHaha's staff(中国大学生程序选拔赛2017年网络大赛)
- 2017中国大学生程序设计竞赛
- 2017中国大学生程序设计竞赛
- 2017中国大学生程序设计竞赛
- 2017中国大学生程序设计竞赛
- 2017中国大学生程序设计竞赛
- 2017中国大学生程序设计竞赛
- Tomcat 调优(二)及 JVM 参数优化
- 关于VS2013下制作和使用静态库和动态库
- Hadoop实例之MaxTemperature
- 使用高效字节流拷贝文件夹
- HDU 6134 Battlestation Operational(莫比乌斯反演+线性筛)
- HDU 6152 2017中国大学生程序设计大赛网络赛 1003
- 构建ubuntu根文件系统
- UltraISO制作U盘系统盘安装CentOS经验分享
- 160. Intersection of Two Linked Lists
- 【JavaSE笔记】多线程(一)进程&线程&Thread&同步代码块
- 解决html页面插入中文数据到mysql数据库出现乱码的情况。
- 【Jiya&Chieng】(贰)CoreDump —— 崩溃前的自拍
- mysql 调优学习笔记
- 英语考试