• 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.(n3000)

    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

    传送门:

    http://acm.hdu.edu.cn/showproblem.php?pid=6152

    题意:

    给你一个有n个顶点的无向图,如果图中存在有三个或者三个以上的顶点两两连通或者两两独立,则输出“Bad Team!” ,否则输出”Great Team!” 。

    思路:

    拉姆齐定理的板子题。拉姆齐定理通俗讲解:https://www.bilibili.com/video/BV17t411x77N

    在了解这个定理之后,当n>=6时,就输出 “Bad Team!”,当n<=5时,就暴力判断,怎么判断呢?

    翻了翻其他题解发现都是通过枚举3点成环来判断,在这里迷了好久。为什么不枚举4个点、5个点呢?

    题目中说是大于等于3个顶点之间两两连通,如果枚举了4个顶点,那么一定包含3个顶点之间相互连通了。

    所以直接枚举3个点就可以。

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    const int maxn = 3005;
    bool vis[maxn][maxn];
    int main()
    
    {
        int t;
        scanf("%d", &t);
        while(t--)
        {
            int n;
            scanf("%d", &n);
    
            for(int i = 1; i <= n; i++)
            {
                for(int j = i + 1; j <= n; j++)
                {
                    int x;
                    scanf("%d", &x);
                    vis[i][j] = vis[j][i] = x;
                }
            }
            if(n >= 6)
                printf("Bad Team!
    ");
            else if(n <= 2)
                printf("Great Team!
    ");
            else
            {
    
                bool flag = false;
                for(int i = 1; i <= n; i++)
                {
                    for(int j = i + 1; j <= n; j++)
                    {
                        for(int k = j + 1; k <= n; k++)
                        {
                            int sum = vis[i][j] + vis[j][k] + vis[i][k];
                            if(sum == 0 || sum == 3)
                                flag = 1;
                        }
                    }
                }
                if(flag)
                    printf("Bad Team!
    ");
                else
                    printf("Great Team!
    ");
            }
        }
    }
  • 相关阅读:
    腾讯云CentOS7学习
    听力词汇发音练习软件
    中缀表达式转后缀表达式
    两个升序序列的中位数
    CentOS配置静态IP
    一种简单的基于图像或激光雷达的道路(赛道)识别程序
    Win10+VS2019 配置YOLOv3
    【算法题】CCF CSP第二题练习(更新中)
    rpm的使用
    SCL
  • 原文地址:https://www.cnblogs.com/yyaoling/p/12777609.html
Copyright © 2020-2023  润新知