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;
}











全部评论

相关推荐

10-31 14:54
已编辑
门头沟学院 算法工程师
点赞 评论 收藏
分享
11-27 12:36
已编辑
门头沟学院 前端工程师
Apries:这个阶段来说,很厉害很厉害了,不过写的简历确实不是很行,优势删掉吧,其他的还行
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务