Friend-Graph

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3072    Accepted Submission(s): 1334

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
Sample Output
Great Team!
#include <iostream>
#include <cstdio>
using namespace std; bool a[][];
int main()
{ int T;
scanf("%d",&T);
while(T>){
int flag=;
int N;
scanf("%d",&N);
for(int i=;i<N;i++){
for(int j=;j<N;j++){
a[i][j]=;
}
}
for(int b=;b<N;b++)
for(int d=b+;d<N;d++){
scanf("%d",&a[b][d]);
a[d][b]=a[b][d];
}
for(int c=;c<N;c++)
for(int q=c+;q<N;q++)
for(int k=q+;k<N;k++){
int ans=a[c][q]+a[q][k]+a[c][k];
if(ans==||ans==){
flag=;
c=N;
q=N;
break;
}
}
if(flag) printf("Great Team!\n");
else printf("Bad Team!\n"); T--;
}
return ;
}
1、这个二维数组a只能用bool定义,用int定义会超,bool只占一个字节
2、bool的取值、和int可以直接相互转换
3、用ans把三个取值加起来,会比直接比较精简
4、注意三个for那里的q、k初始化的值
 
改进:
根据Ramsey定理(组合数学的知识),因为当人数大于等于6时,答案一定是否,所以,可以大大缩小空间
#include <iostream>
#include <cstdio>
using namespace std; bool a[][];
int main()
{ int T;
scanf("%d",&T);
while(T>){
int flag=;
int N;
scanf("%d",&N);
if(N>){
flag=;
}else{
for(int i=;i<N;i++){
for(int j=;j<N;j++){
a[i][j]=;
}
}
for(int b=;b<N;b++)
for(int d=b+;d<N;d++){
scanf("%d",&a[b][d]);
a[d][b]=a[b][d];
}
for(int c=;c<N;c++)
for(int q=c+;q<N;q++)
for(int k=q+;k<N;k++){
int ans=a[c][q]+a[q][k]+a[c][k];
if(ans==||ans==){
flag=;
c=N;
q=N;
break;
}
}
}
if(flag) printf("Great Team!\n");
else printf("Bad Team!\n"); T--;
}
return ;
}

HDU 6152 - Friend-Graph的更多相关文章

  1. HDU 6321 Dynamic Graph Matching

    HDU 6321 Dynamic Graph Matching (状压DP) Problem C. Dynamic Graph Matching Time Limit: 8000/4000 MS (J ...

  2. HDU 5876 Sparse Graph 【补图最短路 BFS】(2016 ACM/ICPC Asia Regional Dalian Online)

    Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  3. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph(暴力搜索)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small ...

  4. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph 暴暴暴暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6152 题意:判定一个无向图是否有三个点的团或者三个点的独立集. 解法:Ramsey theorem,n ...

  5. HDU 5876 Sparse Graph BFS 最短路

    Sparse Graph Problem Description   In graph theory, the complement of a graph G is a graph H on the ...

  6. hdu 4647 Another Graph Game

    题意: 有N个点,M条边. 点有权值, 边有权值. Alice, Bob 分别选点. 如果一条边的两个顶点被同一个人选了, 那么能获得该权值.问 Alice - Bob? 链接:http://acm. ...

  7. HDU 5876 Sparse Graph

    Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  8. 图论(生成树):HDU 5631Rikka with Graph

    Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  9. hdu 5313 Bipartite Graph(dfs染色 或者 并查集)

    Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...

随机推荐

  1. Windows Server 2016 安装虚拟机版黑群晖

    硬件配置 Dell R730 CPU: Intel(R) Xeon(R) CPU E5-2603 v4 @1.70GHz(6 cores) Ram: 16Gb HDD: 系统-600GB SAS X2 ...

  2. 自己手动搭建jenkins教程

    下载列表;  http://updates.jenkins-ci.org/download/war/ 本次下载: http://updates.jenkins-ci.org/download/war/ ...

  3. grep 及正则表达式

    grpe 及正则表达式 文本查找的需要:grep,egrep,fgrepgrep: 根据模式,搜索文本,并将符合模式的文本行显示出来.Pattern : 文本字符以及正则表达式的元字符组合而成的匹配条 ...

  4. missing requires of libmysqlclient.so.18()(64bit)

    错误提示安装依赖的库文件没有找到: libmysqlclient.so.18()(64bit)   解决方法是这样的:   安装mysql-community-libs-compat-5.7.18-1 ...

  5. SpringBoot2.0 项目中使用事务

    参考博客: SpringBoot开启事务常见坑点 另外注意手动回滚事务需要 (1)在业务层方法上添加注解 @Transactional (2)在需要回滚的地方添加代码: TransactionAspe ...

  6. 【Dubbo篇】--Dubbo框架的使用

    一.前述 Dubbo是一种提供高性能,透明化的RPC框架.是阿里开源的一个框架. 官网地址:http://dubbo.io/ 二.架构 组件解释: Provider: 提供者.发布服务的项目.Regi ...

  7. C#反射调用方法实例

    下面是两个反射的实例 案例1: 动态调用类中的方法.传入参数,并获得返回值. xxxx:类名 Event:类中的方法 pra1,pra2,pra3:方法对应的入参 DoRet:方法返回的执行结果 Ty ...

  8. 8-Flink中的窗口

    戳更多文章: 1-Flink入门 2-本地环境搭建&构建第一个Flink应用 3-DataSet API 4-DataSteam API 5-集群部署 6-分布式缓存 7-重启策略 8-Fli ...

  9. 生产线平衡问题的+Leapms线性规划方法

    知识点 第一类生产线平衡问题,第二类生产线平衡问题 整数线性规划模型,+Leapms模型,直接求解,CPLEX求解 装配生产线平衡问题 (The Assembly Line Balancing Pro ...

  10. RDIFramework.NET代码生成器全新V3.5版本发布-重大升级

    发布说明 RDIFramework.NET代码生成器V3.5版本全新震撼推出,相比上次版本,本次发布新增与修改的内容如下: 1.全新增加了WinForm界面代码的生成,可直接生成常用的主界面(集新增. ...