• 51nod 1963 树上Nim


    这题还真就是树上玩 Nim...

    相关知识点就是阶梯博弈,具体可以康这里 →_→ PS:手动搜索阶梯博弈

    然后这题就转化为了多路径的阶梯博弈,这样的话咱定义根节点深度为 0,然后把所有奇数深度点的权值异或一下康康是不是 0 就好了

    但这里要注意别加边 dfs ,直接利用题目性质(fa[i]<i) O(n) 读入的同时得到深度就好了,咱就是加边dfs T 了一发....

    //by Judge
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #define Rg register
    #define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i)
    #define go(u) for(Rg int i=head[u],v=e[i].to;i;v=e[i=e[i].nxt].to)
    #define ll long long
    using namespace std;
    const int M=3e5+3;
    typedef int arr[M];
    #ifndef Judge
    #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    #endif
    char buf[1<<21],*p1=buf,*p2=buf;
    inline int read(){ int x=0,f=1; char c=getchar();
    	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    	for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f;
    } int n,ans; arr d;
    int main(){
    	int T=read();
    	while(T--){ n=read(),ans=0; Rg int x;
    		fp(i,1,n-1) x=read(),d[i]=d[x]^1;
    		fp(i,0,n-1){ x=read();
    			if(d[i]&1) ans^=x;
    		} puts(ans?"win":"lose");
    	} return 0;
    }
    
  • 相关阅读:
    POJ 2752 KMP中next数组的理解
    KMP详解
    HDU 3221 矩阵快速幂+欧拉函数+降幂公式降幂
    POJ 3220 位运算+搜索
    反素数深度分析
    POJ 2886 线段树单点更新
    求反素数的方法
    CV第八课 GPU/CPU
    49. 字母异位词分组
    48. 旋转图像
  • 原文地址:https://www.cnblogs.com/Judge/p/11619821.html
Copyright © 2020-2023  润新知