HDU Friend-Graph(离散数学)

Friend-Graph

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

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!
题意:给出n个人关系,问是否存在三个或者三个以上相互认识或者相互不认识。
题解:根据定理任意6个人之间,指定会出现三个人相互认识或者相互不认识。所以n>=6直接pass,剩下暴力判断即可。
代码:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+100;
const int mod=1e9+7;
const ll INF=1e18;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/***********************************************************/
int t,n,op;
int mp[10][10];
bool flag;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
         memset(mp,0,sizeof(mp));
        scanf("%d",&n);
        for(int i=1;i<n;i++)
        {
            for(int j=1;j<=n-i;j++)
            {
                scanf("%d",&op);
                if(n>=6||n<=2) continue;
                if(op&1)
                {
                    mp[i][i+j]=1;
                    mp[j+i][i]=1;
                }
            }
        }
        flag=false;
        if(n>=6) puts("Bad Team!");
        else if(n<=2)puts("Great Team!");
        else
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=i+1;j<=n;j++)
                {
                    for(int k=j+1;k<=n;k++)
                    {
                        if(mp[i][j]==mp[j][k]&&mp[j][k]==mp[i][k])
                        {
                            flag=true;
                        }
                        if(flag) break;
                    }
                    if(flag) break;
                }
                if(flag) break;
            }
            if(flag) puts("Bad Team!");
            else puts("Great Team!");
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值