HDU 6152 2017中国大学生程序设计大赛网络赛 1003

通过拉姆齐定理解决团队评估问题,判断一个团队是否为好团队。使用算法进行验证,当团队成员数量大于等于6时,必定存在三个成员相互认识或互不认识的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Friend-Graph

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


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.( n3000 )

Then there are n-1 rows. The i th 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!
 题意:一个团队中,如果三个或者三个以上的成员相互认识,或者三个或三个以上的成员之间互相都不认识,那么这个团队就是一个不好的团队,否则就是一个好团队,判断团队的好与坏。
读这个题目的时候,想着用两个数组记录,若大于等于3的话就可以判断了,但是队友讲是环的问题,我没怎么接触过,所以听他讲过以后,就要放弃了,后来,再做的的时候,发现都是那么一回事,但是自己对专业术语可能有点恐惧,so,对术语还是要多加熟悉
比较专业一点的术语如下:

题意:判定一个无向图是否有三个点的团或者三个点的独立集。

题解:Ramsey theorem,n >= 6 直接输出 Bad 否则暴力。

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int a[3007],b[3001];
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        scanf("%d",&n);
        for(int i=1; i<n; i++)
        {
            for(int j=i+1; j<=n; j++)
            {
                scanf("%d",&m);
                if(m==1)
                {
                    a[i]++;
                    a[j]++;
                }
                else
                {
                    b[i]++;
                    b[j]++;
                }
            }
        }
        for(int i=1; i<=n; i++)
        {
            if(a[i]>=3||b[i]>=3)
            {
                printf("Bad Team!\n");
                break;
            }
            else
            {
                printf("Great Team!\n");
                break;
            }

        }
    }
    return 0;
}

利用拉姆齐定理用起来好快,差不多只有0MS,现在明白了,定理和算法的重要性
对拉姆齐定理简单说一下吧,其实我也是一知半解,讲讲为什么n>=6的时候,直接是bad team吧!
因为当n>=6的时候,必定有一个三个或三个以上的成员互相认识,或者三个或三个以上的成员互相不认识

证明如下:首先,把这6个人设为A、B、C、D、E、F六个点。由A点可以引出AB、AC、AD、AE、AF五条线段。设:如果两个人认识,则设这两个人组成的线段为红色;如果两个人不认识,则设这两个人组成的线段为蓝色。

由抽屉原理可知:这五条线段中至少有三条是同色的。不妨设AB、AC、AD为红色。若BC或CD为红色,则结论显然成立。若BC和CD均为蓝色,则若BD为红色,则一定有三个人相互认识;若BD为蓝色,则一定有三个人互相不认识。

折叠
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int a[3007],b[3001];
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        scanf("%d",&n);
        if(n>=6)
        {
            printf("Bad Team!\n");
        }
        else if(n<=2)
        {
            printf("Bad Team!\n");
        }
        else
        {
            for(int i=1; i<n; i++)
            {
                for(int j=i+1; j<=n; j++)
                {
                    scanf("%d",&m);
                    if(m==1)
                    {
                        a[i]++;
                        a[j]++;
                    }
                    else
                    {
                        b[i]++;
                        b[j]++;
                    }
                }
            }
            for(int i=1; i<=n; i++)
            {
                if(a[i]>=3||b[i]>=3)
                {
                    printf("Bad Team!\n");
                    break;
                }
                else
                {
                    printf("Great Team!\n");
                    break;
                }

            }
        }

    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值