Friend-Graph

Friend-Graph

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

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

在一个team里面,有三个或者三个以上的人是朋友,有三个或者三个以上的人不是朋友,都会是一个bad team,其余的是great team!

这是组队赛里做出来的题目,当时,看到题目,第一想法时并查集,但是后来发现实现不了,就又看了一下题,然后,又和队友商讨了一下,决定用bfs,后来还是队友敲的~~~(这个方法其实————)就不说了,来找一下简单的方法吧!

当时看到题目的时候,我的脑海里有那么一瞬想的是当多于六个人的时候,应该会满足三个或三个以上的人是朋友,或者三个或者三个以上的人不是朋友,但是,没有深入的去想,就那样一闪而过了~

因为当n>=6的时候,必定有一个三个或三个以上的成员互相认识,或者三个或三个以上的成员互相不认识
证明如下:首先,把这6个人设为A、B、C、D、E、F六个点。由A点可以引出AB、AC、AD、AE、AF五条线段。设:如果两个人认识,则设这两个人组成的线段为红色;如果两个人不认识,则设这两个人组成的线段为蓝色。所以,可知,至少有三条线段时同一种颜色的,也就是符合bad的条件!(这里就不给出代码了)

#include <bits/stdc++.h>
using namespace std;
int a[3456], b[3456];
int main()
{
    int T, n, m;
    cin>>T;
    while(T--)
    {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        cin>>n;
        for(int i=1; i<n; i++)
        {
            for(int j=i+1; j<=n; j++)
            {
                cin>>m;
                if(m==1)//是朋友
                {
                    a[i]++;
                    a[j]++;
                }
                else//不是朋友
                {
                    b[i]++;
                    b[j]++;
                }
            }
        }
        for(int i=1; i<=n; i++)
        {
            if(a[i]>=3||b[i]>=3)
            {
                printf("Bad Team!\n");
                break;
            }
            else
            {
                printf("Great Team!\n");
                break;
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值