欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

2017 ccpc 网络赛 Friend-Graph

程序员文章站 2022-04-28 14:47:33
...

Friend-Graph

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

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!

Source
2017中国大学生程序设计竞赛 - 网络选拔赛

Ramsey定理
6个人必然有3个互相认识或者3个互不相识

#include <iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
#include<queue>

using namespace std;
const int mmax = 400012 ;
const int inf = 0x3f3f3f3f;
#define Q(x,y) memset(x,y,sizeof(x));
bool tu[3001][3001];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int x;
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                scanf("%d",&x);
                tu[i][j] =tu[j][i]=x;
            }
        }
        int f = 0;
        for(int k=1;k<=n;k++)
        {
            for(int i=k+1;i<=n;i++)
            {
                for(int j=i+1;j<=n;j++)
                {
                   if(k==i||k==j)continue;
                    if(tu[i][k]&&tu[k][j]&&tu[i][j])
                    {
                        f = 1;
                        break;
                    }
                    else if(!tu[i][k]&&!tu[k][j]&&!tu[i][j])
                    {
                        f = 1;
                        break;
                    }
                }
                if(f)break;
            }
            if(f)break;
        }
        if(!f)printf("Great Team!\n");
        else printf("Bad Team!\n");
    }
}

方法2


#include <iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
#include<queue>

using namespace std;
const int mmax = 400012 ;
const int inf = 0x3f3f3f3f;
#define Q(x,y) memset(x,y,sizeof(x));
vector<int>a[3010];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int x;
        int f =0;
        for(int i=1;i<=n;i++)
            a[i].clear();
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                scanf("%d",&x);
                if(f)continue;
                a[i].push_back(x);
                for(int k=1;k<i;k++)
                {
                    if(x==1)
                    {
                        if(a[k][i-k-1]==1&&a[k][j-k-1]==1)
                       {
                        f =1;
                        break;
                        }
                    }

                    else if(a[k][i-k-1]==0&&a[k][j-k-1]==0)
                    {
                        f =1;
                        break;
                    }
                }
            }
        }
        if(!f)printf("Great Team!\n");
        else printf("Bad Team!\n");
    }
}
//这样对于3 4 而言 比较的是 1 3 ,1 4和2 3 ,2 4

2017 ccpc 网络赛 Friend-Graph