zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    python写入csv文件中文乱码解决方案
    高质量代码有三要素:可读性、可维护性、可变更性
    CFile
    BMP格式图像的显示
    SAP BW 学习笔记(一)
    SAP BW 学习笔记(五)
    SAP BW 学习笔记(二)
    SAP BW 学习笔记(三)
    SAP BW 学习笔记(四)
    CRM 5.0 Marketing – BW integrated topics summary
  • 原文地址:https://www.cnblogs.com/heimao5027/p/6038059.html
Copyright © 2011-2022 走看看