HDU 6152 Friend-Graph

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 1 0 
0 0 
1

Sample Output

Great Team!

题目大意:

输入的第一行给出测试用例T的数量; (T <= 15) 
每个案件的第一行应包含一个整数n,表示团队人数(n≤3000) 
那么有n-1行。 第i行应包含n-i个数字,其中a[i][j]表示成员i与成员j + i之间的关系。 0表示这两个人不是朋友。 1表示这两个人是朋友。在一个有n个成员的团队中,如果有三个或更多的成员不是彼此的朋友,或者有三个或更多的成员是彼此的朋友。符合以上条件的球队可以称为坏队,否则,球队是一支好球队。 
这道题给的时候够大可以直接暴力,不过这道题卡内存,刚开始用int型超内存,后来改为bool类型就过了。

c++

内存超限代码

#include<iostream>
#include<cstdio>
using namespace std;
int m[3010][3010];
int dg(int n)
{
    int a,b,c,d,e;
    for(c=1;c<=n;c++)
    {
        for(d=c+1;d<=n;d++)
        {
            for(a=d+1;a<=n;a++)
            {
                if(m[c][d]==m[c][a]&&m[c][a]==m[d][a]&&m[c][d]==m[d][a])
                    return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int a,b,c,d,e,f;
    scanf("%d",&a);
    while(a--)
    {
        scanf("%d",&b);
        for(c=1;c<b;c++)
        {
            for(d=1+c;d<=b;d++)
            {
                scanf("%d",&m[c][d]);
                m[d][c]=m[c][d];
            }
        }
        e=dg(b);
        if(e==0)
            printf("Great Team!\n");
        else
            printf("Bad Team!\n");
    }
    return 0;
}

AC代码

#include<iostream>
#include<cstdio>
using namespace std;
bool m[3010][3010];
int dg(int n)
{
    int a,b,c,d,e;
    for(c=1;c<=n;c++)
    {
        for(d=c+1;d<=n;d++)
        {
            for(a=d+1;a<=n;a++)
            {
                if(m[c][d]==m[c][a]&&m[c][a]==m[d][a]&&m[c][d]==m[d][a])
                    return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int a,b,c,d,e,f;
    scanf("%d",&a);
    while(a--)
    {
        scanf("%d",&b);
        for(c=1;c<b;c++)
        {
            for(d=1+c;d<=b;d++)
            {
                scanf("%d",&f);
                if(f==1)
                    m[d][c]=m[c][d]=false;
                else
                    m[d][c]=m[c][d]=true;
            }
        }
        e=dg(b);
        if(e==0)
            printf("Great Team!\n");
        else
            printf("Bad Team!\n");
    }
    return 0;
}











全部评论

相关推荐

粗心的雪碧不放弃:纯学历问题,我这几个月也是一直优化自己的简历,后来发现优化到我自己都觉得牛逼的时候,发现面试数量也没有提升,真就纯学历问题
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务