zoukankan      html  css  js  c++  java
  • Eliminate the Conflict HDU

    题意:

      石头剪刀布 分别为1、2、3,有n轮,给出了小A这n轮出什么,然后m行,每行三个数a b k,如果k为0 表示小B必须在第a轮和第b轮的策略一样,如果k为1 表示小B在第a轮和第b轮的策略不一样,如果又一轮小B输了,那整个就输了,求小B能否战胜小A

    解析:

      写出来矛盾的情况  建图就好啦

    可能我建的麻烦了。。。不过。。我喜欢 hhhhh

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <cctype>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <bitset>
    #define rap(i, a, n) for(int i=a; i<=n; i++)
    #define rep(i, a, n) for(int i=a; i<n; i++)
    #define lap(i, a, n) for(int i=n; i>=a; i--)
    #define lep(i, a, n) for(int i=n; i>a; i--)
    #define rd(a) scanf("%d", &a)
    #define rlld(a) scanf("%lld", &a)
    #define rc(a) scanf("%c", &a)
    #define rs(a) scanf("%s", a)
    #define pd(a) printf("%d
    ", a);
    #define plld(a) printf("%lld
    ", a);
    #define pc(a) printf("%c
    ", a);
    #define ps(a) printf("%s
    ", a);
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 1e5 + 10, INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
    int n, m;
    int a[maxn];
    vector<int> G[maxn];
    int sccno[maxn], vis[maxn], low[maxn], scc_clock, scc_cnt;
    stack<int> S;
    void init()
    {
        mem(sccno, 0);
        mem(vis, 0);
        mem(low, 0);
        scc_clock = scc_cnt = 0;
        for(int i = 0; i < maxn; i++) G[i].clear();
    }
    
    void dfs(int u)
    {
        low[u] = vis[u] = ++scc_clock;
        S.push(u);
        for(int i = 0; i < G[u].size(); i++)
        {
            int v = G[u][i];
            if(!vis[v])
            {
                dfs(v);
                low[u] = min(low[u], low[v]);
            }
            else if(!sccno[v])
            {
                low[u] = min(low[u], vis[v]);
            }
        }
        if(low[u] == vis[u])
        {
            scc_cnt++;
            for(;;)
            {
                int x = S.top(); S.pop();
                sccno[x] = scc_cnt;
                if(x == u) break;
            }
        }
    }
    
    bool check()
    {
        for(int i = 0; i < n * 2; i += 2)
            if(sccno[i] == sccno[i + 1])
            {
                return false;
            }
        return true;
    }
    
    
    int main()
    {
        int T, kase = 0;
        cin >> T;
        while(T--)
        {
            init();
            int u, v, w;
            cin >> n >> m;
            for(int i = 0; i < n; i++)
                cin >> a[i];
            for(int i = 1; i <= m; i++)
            {
                cin >> u >> v >> w;
                u--, v--;
                int x = a[u], y = a[v];
                if(w == 1)
                {
                    if(x == y)
                    {
                        G[u << 1].push_back(v << 1 | 1);
                        G[v << 1 | 1].push_back(u << 1);
                        G[u << 1 | 1].push_back(v << 1);
                        G[v << 1].push_back(u << 1 | 1);
                    }
                    else if(x != y)
                    {
                        if(x == 1 && y == 2 || y == 1 && x == 2)
                        {
                            if(y == 1 && x == 2)
                                swap(u, v);
                            G[u << 1 | 1].push_back(v << 1 | 1), G[v << 1].push_back(u << 1);
                        }
                        else if(x == 1 && y == 3 || y == 1 && x == 3)
                        {
                            if(y == 1 && x == 3)
                                swap(u, v);
                            G[v << 1 | 1].push_back(u << 1 | 1), G[u << 1].push_back(v << 1);
                        }
                        else if(x == 2 && y == 3 || x == 3 && y == 2)
                        {
                            if(x == 3 && y == 2)
                                swap(u, v);
                            G[u << 1 | 1].push_back(v << 1 | 1), G[v << 1].push_back(u << 1);
                        }
                    }
                }
                else
                {
                    if(x == y)
                    {
                        G[u << 1].push_back(v << 1), G[u << 1 | 1].push_back(v << 1 | 1);
                        G[v << 1].push_back(u << 1), G[v << 1 | 1].push_back(u << 1 | 1);
                    }
                    else
                    {
                        if(x == 1 && y == 2 || x == 2 && y == 1)
                        {
                            if(x == 2 && y == 1) swap(u, v);
                            G[u << 1 | 1].push_back(v << 1), G[v << 1].push_back(u << 1 | 1);
                            G[u << 1].push_back(u << 1 | 1), G[v << 1 | 1].push_back(v << 1);
                        }
                        else if(x == 1 && y == 3 || x == 3 && y == 1)
                        {
                            if(x == 3 && y == 1) swap(u, v);
                            G[u << 1].push_back(v << 1 | 1), G[v << 1 | 1].push_back(u << 1);
                            G[u << 1 | 1].push_back(u << 1), G[v << 1].push_back(v << 1 | 1);
                        }
                        else if(x == 2 && y == 3 || y == 2 && x == 3)
                        {
                            if(y == 2 && x == 3) swap(u, v);
                            G[u << 1 | 1].push_back(v << 1), G[v << 1].push_back(u << 1 | 1);
                            G[u << 1].push_back(u << 1 | 1), G[v << 1 | 1].push_back(v << 1);
                        }
                    }
                }
            }
            for(int i = 0; i < n * 2; i++)
                if(!vis[i]) dfs(i);
            printf("Case #%d: ", ++kase);
            if(check())
            {
                cout << "yes" << endl;
            }
            else cout << "no" << endl;
        }
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    python3-cookbook笔记:第十三章 脚本编程与系统管理
    python3-cookbook笔记:第十二章 并发编程
    python3-cookbook笔记:第十章 模块与包
    python3-cookbook笔记:第九章 元编程
    python3-cookbook笔记:第八章 类与对象
    python3-cookbook笔记:第七章 函数
    python3-cookbook笔记:第六章 数据编码和处理
    python3-cookbook笔记:第五章 文件与IO
    python中的列表推导式
    python的类属性、实例属性、类方法、静态方法
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9807300.html
Copyright © 2011-2022 走看看