zoukankan      html  css  js  c++  java
  • 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!
    ");
            }
        }
    }
  • 相关阅读:
    [洛谷P2523] HAOI2011 Problem c
    [CF156D] Clues
    [洛谷P4769] NOI2018 冒泡排序
    [CF605E] Intergalaxy Trips
    [洛谷P4492] HAOI2018 苹果树
    [洛谷P3349] ZJOI2016 小星星
    [洛谷P4336] SHOI2016 黑暗前的幻想乡
    [洛谷P5364] SNOI2017 礼物
    [洛谷P2606] ZJOI2010 排列计数
    [洛谷P6078] CEOI2004 candy
  • 原文地址:https://www.cnblogs.com/yyaoling/p/12777609.html
Copyright © 2011-2022 走看看