hdu 5963(找规律)

来源:互联网 发布:大淘客cms建站教程 编辑:程序博客网 时间:2024/06/01 03:59

这题就不是一个博弈论,无论玩家做出什么决策,影响都是一样的,游戏会在固定的步数结束。所以成了一道找规律的题目。与根节点相连的边权值为一的个数决定了 胜负。

偶数,后手胜。

奇数,先手胜。

    #include <iostream>    #include <algorithm>    #include <string.h>    #include <stdio.h>    #include <vector>    using namespace std;    int temp[40005];    vector<int> d[40005];    int main(){        int t;        scanf("%d",&t);        while(t--){            int n,m;            scanf("%d %d",&n,&m);            memset(temp,0,sizeof(temp));            memset(d,0,sizeof(d));            for(int i=0;i<n-1;i++){                int a,b,c;                scanf("%d %d %d",&a,&b,&c);                if(c==1){                    temp[a]++;                    temp[b]++;                    d[a].push_back(b);                    d[b].push_back(a);                }            }            while(m--){                int q;                scanf("%d",&q);                if(q==0){                    int x;                    scanf("%d",&x);                    if(temp[x]%2==0)                        puts("Boys win!");                    else                        puts("Girls win!");                }                else{                    int x,y,z;                    scanf("%d %d %d",&x,&y,&z);                    vector<int>::iterator it=find(d[x].begin(),d[x].end(),y);                    vector<int>::iterator it1=find(d[y].begin(),d[y].end(),x);                    if(it!=d[x].end()&&z==0){                        temp[x]--;                        temp[y]--;                        d[x].erase(it);                        d[y].erase(it1);                    }                    if(it==d[x].end()&&z==1){                        temp[x]++;                        temp[y]++;                        d[x].push_back(y);                        d[y].push_back(x);                    }                }            }        }        return 0;    }


原创粉丝点击