2017中国大学生程序设计竞赛 - 网络选拔赛 1003 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
4
1 1 0
0 0
1

Sample Output
Great Team!

题意:

有n个人组成的一个团队,彼此之间可能存在为朋友或者不为朋友的关系,如果其中的三个或三个以上的人彼此都不是朋友或则彼此都是朋友,则这个团队就是“Bad Team!”,否则的话这个团队就是”Great Team!” 。

给出这n个人彼此之间的关系(“1”代表两个人是朋友,“0”代表两个人不是朋友),判断这个团队是”Great Team!” 还是Bad Team!”。

分析:

我的天,刚开始想着用并查集写,有关系的放到一个集合里,没有关系的放到另外的一个集合里面,然后每次插入一条关系的时候,如果从对应的集合中能找到这两个人,那么肯定就是Bad Team!”

可能那个细节没有处理好,反正是w了。

后来发现完全暴力就可以过,真是不想说啥了。


#include<iostream>
#include<cstdio>
#include<string.h>

using namespace std;

bool con[3010][3010];
int n;
bool judge( )
{

    for(int i=1; i<=n; i++)
    {
        for(int j=i+1; j<=n; j++)
        {
            for(int k=j+1; k<=n; k++)
            {
                ///如果三个人之间彼此有相同的关系,就已经可以确定是一个Bad Team!
                if(con[i][j]==con[i][k]&&con[j][i]==con[j][k]&&con[k][i]==con[k][j])
                    return false;
            }
        }
    }
    return true;
}
int main()
{
    int T, num;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1; i<n; i++)
        {
            for(int j=i+1; j<=n; j++)
            {
                scanf("%d",&num);
                if(num==1)
                    con[i][j]=con[j][i]=false;///i与j之间有朋友关系
                else
                    con[i][j]=con[j][i]=true;///i与j之间没有朋友关系
            }
        }

        if(judge())
            printf("Great Team!\n");
        else
            printf("Bad Team!\n");
    }
    return 0;
}

转载于:https://www.cnblogs.com/cmmdc/p/7397646.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值