zoukankan      html  css  js  c++  java
  • 2017中国大学生程序设计竞赛

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6152

    题意:判定一个无向图是否有三个点的团或者三个点的独立集。

    解法:Ramsey theorem,n >= 6 直接输出 Bad 否则暴力。我是直接暴力,加个break优化就好了。

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int maxn = 3e3+3;
    bool w[maxn][maxn];
    bool check(int n){
        for(int i=1; i<=n; i++){
            for(int j=i+1; j<=n; j++){
                for(int k=j+1; k<=n; k++){
                    if(w[i][j]==w[i][k]&&w[i][k]==w[j][k]&&w[i][j]==w[j][k]){
                        return true;
                    }
                }
            }
        }
        return false;
    }
    struct FastIO
    {
        static const int S = 1310720;
        int wpos;
        char wbuf[S];
        FastIO() : wpos(0) {}
        inline int xchar()
        {
            static char buf[S];
            static int len = 0, pos = 0;
            if(pos == len)
                pos = 0, len = fread(buf, 1, S, stdin);
            if(pos == len)
                exit(0);
            return buf[pos ++];
        }
        inline unsigned long long xuint()
        {
            int c = xchar();
            unsigned long long x = 0;
            while(c <= 32)
                c = xchar();
            for(; '0' <= c && c <= '9'; c = xchar())
                x = x * 10 + c - '0';
            return x;
        }
        inline long long xint()
        {
            long long s = 1;
            int c = xchar(), x = 0;
            while(c <= 32)
                c = xchar();
            if(c == '-')
                s = -1, c = xchar();
            for(; '0' <= c && c <= '9'; c = xchar())
                x = x * 10 + c - '0';
            return x * s;
        }
        inline void xstring(char *s)
        {
            int c = xchar();
            while(c <= 32)
                c = xchar();
            for(; c > 32; c = xchar())
                * s++ = c;
            *s = 0;
        }
        inline double xdouble()
        {
            bool sign = 0;
            char ch = xchar();
            double x = 0;
            while(ch <= 32)
                ch = xchar();
            if(ch == '-')
                sign = 1, ch = xchar();
            for(; '0' <= ch && ch <= '9'; ch = xchar())
                x = x * 10 + ch - '0';
            if(ch == '.')
            {
                double tmp = 1;
                ch = xchar();
                for(; ch >= '0' && ch <= '9'; ch = xchar())
                    tmp /= 10.0, x += tmp * (ch - '0');
            }
            if(sign)
                x = -x;
            return x;
        }
        inline void wchar(int x)
        {
            if(wpos == S)
                fwrite(wbuf, 1, S, stdout), wpos = 0;
            wbuf[wpos ++] = x;
        }
        inline void wint(long long x)
        {
            if(x < 0)
                wchar('-'), x = -x;
            char s[24];
            int n = 0;
            while(x || !n)
                s[n ++] = '0' + x % 10, x /= 10;
            while(n--)
                wchar(s[n]);
        }
        inline void wstring(const char *s)
        {
            while(*s)
                wchar(*s++);
        }
        inline void wdouble(double x, int y = 6)
        {
            static long long mul[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000LL, 100000000000LL, 1000000000000LL, 10000000000000LL, 100000000000000LL, 1000000000000000LL, 10000000000000000LL, 100000000000000000LL};
            if(x < -1e-12)
                wchar('-'), x = -x;
            x *= mul[y];
            long long x1 = (long long) floorl(x);
            if(x - floor(x) >= 0.5)
                ++x1;
            long long x2 = x1 / mul[y], x3 = x1 - x2 * mul[y];
            wint(x2);
            if(y > 0)
            {
                wchar('.');
                for(size_t i = 1; i < y && x3 * mul[i] < mul[y]; wchar('0'), ++i);
                wint(x3);
            }
        }
        ~FastIO()
        {
            if(wpos)
                fwrite(wbuf, 1, wpos, stdout), wpos = 0;
        }
    } io;
    
    int main()
    {
        int T,n,m;
        T = io.xint();
        while(T--)
        {
            n = io.xint();
            for(int i=1; i<n; i++){
                for(int j=i+1; j<=n; j++){
                    m = io.xint();
                    if(m == 1) w[i][j]=w[j][i]=false;
                    else w[i][j]=w[j][i]=true;
                }
            }
            if(check(n)){
                puts("Bad Team!");
            }
            else{
                puts("Great Team!");
            }
        }
        return 0;
    }
    
  • 相关阅读:
    应用express mockjs模拟前端json数据接口
    sublime text3 cssrem 快速px转rem插件
    python多版本共存问题(以2.7和3.5系列版本为例)
    免费的大数据学习资料,这一份就足够
    大数据时代的三大趋势和三大困境
    四个填空题,你会如何回答怎么学大数据?看看阿里的大数据学习!
    为什么学习大数据,大数据专家写给大数据分析学习者的10个理由
    你知道大数据强大在哪里!!!你永远也不会猜到
    大数据的强大你知道多少
    零基础入门到精通:Python大数据与机器学习之Pandas-数据操作
  • 原文地址:https://www.cnblogs.com/spfa/p/7397731.html
Copyright © 2011-2022 走看看