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. 4.JAVA-数组、String详解

    1.数组 public class Test{ public static void main(String args[]){ int[] intArray = new int[] {1,4,3,2, ...

  2. String字符串类总结

    object类 int hashCode() Object定义的hashCode方法能为不同对象返回不同的整数.实际上是把JVM给对象分配的地址转化为整数,确保了逻辑上的唯一性.而转化的散列算法,可能 ...

  3. PHP中反射的简单实用(动态代理)

    <?php class mysql{ function connect($db){ echo "连接mysql数据库${db[0]} \r\n"; } } class ora ...

  4. 提升机器学习数学基础,这7本书一定要读-附pdf资源

    文章发布于公号[数智物语] (ID:decision_engine),关注公号不错过每一篇干货. 来源 | KDnuggets 作者 | Ajit Jaokar 转自 | 新智元 编辑 | 大明 [编 ...

  5. .NET Framework和 .Net Core实现不一致的API之 `EmailAddressAttribute`

    .NET Framework和 .Net Core实现不一致的API之 EmailAddressAttribute Intro 现在我们的类库项目大多是 NETStandard2.0 项目,但是 ne ...

  6. sql server2005安装时报 ‘服务无法启动’

    SQL server服务无法启动的原因分析: 在安装SQL 2005标准版(不多于四个CPU)和企业版(无限制)时,CPU的总核数必须是2的n次方.即核心数为1,2,4,8,16,32依次类推.因BL ...

  7. Windows Cluster 添加新节点--验证报错

    今天给既有Windows Cluster 添加节点时,验证总是不通过.报错信息为 防火墙未正确配置为故障转移群集.现将处理步骤汇总如下. 1.错误具体信息 报错的位置 --[验证警告] 的步骤中发现错 ...

  8. Linux 虚拟网络设备 veth-pair 详解,看这一篇就够了

    本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. 前面这篇文章介 ...

  9. 第一周 IP通信基础学习回顾

    这周的课程首先让我们学习了计算机网络概述,了解计算机网络的定义和功能分别是:资源共享,信息传输与集中处理,负载均衡与分布处理,综合信息服务.同时也对计算机网络的演进,计算机网络的分类,计算机网络的性能 ...

  10. [Abp vNext 源码分析] - 3. 依赖注入与拦截器

    一.简要说明 ABP vNext 框架在使用依赖注入服务的时候,是直接使用的微软提供的 Microsoft.Extensions.DependencyInjection 包.这里与原来的 ABP 框架 ...