HDU-6125-Friend-Graph-2017CCPC网络赛(图论,拉姆齐定理-组合数学)

Friend-Graph

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

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!

 

题意:如果有三个及以上的人彼此认识或者三个及以上的人彼此不认识就是Bad Team!,否则就是Great Team!。正常思路就是建图暴力跑,然而3000*3000的矩阵会爆内存,瞎暴力很容易TLE。

 

拉姆齐定理

在组合数学上, 拉姆齐(Ramsey)定理是要解决以下的问题:要找这样一个最小的数n ,使得n个人中必定有k个人相识或l个人互不相识。

通俗表述

6 个人中至少存在3人相互认识或者相互不认识。

该定理等价于证明这6个顶点的完全图的边,用红、蓝二色任意着色,必然至少存在一个红色边三角形,或蓝色边三角形。

验证推导

R(3,3)=6

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

 

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

好了,现在再看这个题简直就水的不行了,正常建图要int类型3000*3000的矩阵会爆内存,暴力跑for循环还会TLE,现在根本都不存在了。

#include <bits/stdc++.h>
using namespace std;

bool G[6][6];

int main()
{
    int T;
    scanf("%d", &T);
    while( T-- )
    {
        int n;
        scanf("%d", &n);
        for( int i=1; i<=n; i++ )
        {
            for( int j = i + 1; j <= n; j++ )
            {
                int e;
                scanf("%d", &e);
                if( n <= 6 )
                    G[j][i] = G[i][j] = e;
            }
        }

        if(n < 3)
        {
            printf("Great Team!\n");
            continue;
        }

        if(n >= 6)
        {
            printf("Bad Team!\n");
            continue;
        }

        bool flag = false;
        for( int a = 1; a <= n; a++ )
            for( int b = a + 1; b <= n; b++ )
                for( int c = b + 1; c <= n; c++ )
                    if( (G[a][b] && G[a][c] && G[b][c]) ||
                        (!G[a][b] && !G[a][c] && !G[b][c]) )
                        flag = true;
        
        if( flag )  printf("Bad Team!\n");
        else printf("Great Team!\n");
    }
    return 0;
}

转载于:https://www.cnblogs.com/gaojinmanlookworld/p/10586851.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值