• HDU 5963 博弈


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

    题目大意:中文题

    思路:看ICPC camp好了,简单易懂:https://async.icpc-camp.org/d/628-2016     上面的C题

    //看看会不会爆int!数组会不会少了一维!
    //取物问题一定要小心先手胜利的条件
    #include <bits/stdc++.h>
    using namespace std;
    #pragma comment(linker,"/STACK:102400000,102400000")
    #define LL long long
    #define ALL(a) a.begin(), a.end()
    #define pb push_back
    #define mk make_pair
    #define fi first
    #define se second
    #define haha printf("haha
    ")
    const int maxn = 40000 + 5;
    struct Node{
        int to, val;
    };
    vector<Node> G[maxn];
    int n, m;
    int ans[maxn];
    
    int main(){
        int t; cin >> t;
        while (t--){
            scanf("%d%d", &n, &m);
            for (int i = 1; i <= n; i++) G[i].clear();
            for (int i = 1; i < n; i++){
                int u, v, val;
                scanf("%d%d%d", &u, &v, &val);
                G[u].pb(Node{v, val}); G[v].pb(Node{u, val});
            }
            memset(ans, 0, sizeof(ans));
            for (int i = 1; i <= n; i++){
                for (int j = 0; j < G[i].size(); j++){
                    ans[i] += G[i][j].val;
                }
            }
            for (int i = 1; i <= m; i++){
                int ty; scanf("%d", &ty);
                if (ty == 0){
                    int root; scanf("%d", &root);
                    if (ans[root] % 2) printf("Girls win!
    ");
                    else printf("Boys win!
    ");
                }
                else if (ty == 1){
                    int u, v, val;
                    scanf("%d%d%d", &u, &v, &val);
                    for (int j = 0; j < G[u].size(); j++){
                        if (G[u][j].to == v){
                            if (val == G[u][j].val) break;
                            else {
                                G[u][j].val = val;
                                if (val == 1) ans[u]++, ans[v]++;
                                else ans[u]--, ans[v]--;
                            }
                        }
                    }
                    for (int j = 0; j < G[v].size(); j++){
                        if (G[v][j].to == u){
                            G[v][j].val = val;
                            break;
                        }
                    }
                }
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    form表单提交target属性使用
    window.showModalDialog
    mybaits中date类型显示时分秒(orcle数据库)
    mybatis中in查询
    偷懒的inline-block解决方法
    10. python单元测试(一)
    9. Request & 爬虫
    8. 类与对象
    7. python异常处理&异常基类学习
    6. IO及文件操作
  • 原文地址:https://www.cnblogs.com/heimao5027/p/6038059.html
Copyright © 2020-2023  润新知