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. python:前端(HTML)+后端(Django)+数据库(MySQL)

    1.创建一个html文件用于简单的网页注册demo <!DOCTYPE html> <html lang="en"> <head> <me ...

  2. vue之$root,$parent

    $root vue状态管理使用vuex,如果项目不大,逻辑不多,name我们没必要用vuex给项目增加难度,只需要用$root设置vue实例的data就行了,如下 main.js new Vue({ ...

  3. git使用笔记1:结合Github远程仓库管理项目

    git是一个十分好用的版本控制工具,我们经常在本地使用git进行项目开发,Git 并不像 SVN 那样有个中心服务器,如果想要通过 Git 分享你的代码或者与其他开发人员合作,就需要将数据放到一台其他 ...

  4. FPGA高速ADC接口实战——250MSPS采样率ADC9481

    一.前言 最近忙于硕士毕业设计和论文,没有太多时间编写博客,现总结下之前在某个项目中用到的一个高速ADC接口设计部分.ADC这一器件经常用于无线通信.传感.测试测量等领域.目前数字系统对高速数据采集的 ...

  5. requirement failed: Unacceptable value for property 'kafka.timeline.metrics.host_in_memory_aggregation', boolean values must be either 'true' or 'false

    requirement failed: Unacceptable value for property 'kafka.timeline.metrics.host_in_memory_aggregati ...

  6. python 基础语法梳理(二)

    1.gevent使用 # -*- coding: utf-8 -*- import gevent import platform from gevent import subprocess def _ ...

  7. Scala的类层级讲解

    Scala的类层级 Scala里,每个类都继承自通用的名为Any的超类. 因为所有的类都是Any的子类,所以定义在Any中的方法就是"共同的"方法:它们可以被任何对象调用. Sca ...

  8. 经典排序算法 — C# 版(上)

    提起排序,与我们的息息相关,平时开发的代码少不了排序. 经典的排序算法又非常多,我们怎么评价一个排序算法的好坏呢? 其实可以这样想,要细致的比较排序算法好坏,那我们就从多方面尽可能详细的对比 一.效率 ...

  9. Json,Gson,Ajax基础知识

    //json 是一种轻量级的文本格式,解析简单,他也是一键值来存,数据与数据的分割是以,来分割 //{} 看到大括号就是一个对象,[]代表集合 ,基本上所有数据的交互都是以json格式来进行传递的 / ...

  10. C/C++性能测试工具GNU gprof

    代码剖析(Code profiling)程序员在优化软件性能时要注意应尽量优化软件中被频繁调用的部分,这样才能对程序进行有效优化.使用真实的数据,精确的分析应用程序在时间上的花费的行为就成为_代码剖析 ...