Friend-Graph---枚举
来源:互联网 发布:python安装后怎么用 编辑:程序博客网 时间:2024/06/10 07:55
题目
http://acm.hdu.edu.cn/showproblem.php?pid=6152
Friend-Graph
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1297 Accepted Submission(s): 666
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
4
1 1 0
0 0
1
题意:有n个人,然后给出,第i个人与他后面的人的关系,如果n个人里面,有三个或者三个以上的人是好朋友或者不是朋友,那么这个队就叫“bad team”.否则叫”good team”。记住是只这三个人是不是好朋友,或者都不认识,不是找三对不是好朋友的。
思路:
枚举,稍微改善一下,没超时。一个注意的地方:如果用int去定义的话,数组太大了,所以用bool。用字符去定义比较麻烦,以后可以注意一下。
代码:
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;bool a[3001][3001];//用bool会更好一点 int main(){ int i,j,k; int t; int flag; scanf("%d",&t); int n; int c; while(t--){ flag=0; scanf("%d",&n); memset(a,0,sizeof(a)); for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ scanf("%d",&c); a[i][j]=(bool)c; } } for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ for(k=j+1;k<n;k++){ if(a[i][k]&&a[i][j]&&a[j][k]) { flag=1; break; } if(a[i][j]==0&&a[i][k]==0&&a[j][k]==0){ flag=1; break; } } if(flag) break; } if(flag) break; } if(flag) printf("Bad Team!\n"); else printf("Great Team!\n"); } return 0;}
- Friend-Graph---枚举
- Friend-Graph(暴力枚举)
- Friend-Graph
- Friend-Graph
- Friend-Graph
- Friend-Graph
- Friend-Graph
- Friend-Graph
- HDU_6152 Friend-Graph 【暴力】
- Friend-Graph (暴力)
- HDU6152 Friend-Graph【模拟】
- HDU 6152 Friend-Graph
- HDU 6152 Friend-Graph
- Friend-Graph(hdoj6152)
- Friend-Graph 1003
- hdu-6152 Friend-Graph
- hdu6152 Friend-Graph
- HDU 6152 Friend-Graph
- 怎么进行面向对象设计(二)
- OpenCV + CentOS开发环境搭建
- 孙鑫C++教程学习记录
- Android工程师之Android面试大纲
- 2017年千禧一代奢侈品用户购买行为分析
- Friend-Graph---枚举
- C#/.Net
- android.mk中引用第三方库的方法
- Java中使用Jedis操作Redis
- HDU 4787GRE Words Revenge
- 五星评价
- 运行工程 java.net.BindException: Address already in use: JVM_Bind <null>:8080
- WebView的设置
- 动态添加行及之后的排序