zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    vue-router路由知识补充
    vue-router路由模式详解
    Linq To Sql的各种查询
    消息队列系列(四):Rabbitmq常用命令行
    产品发布之我见
    利用LogParser分析IIS日志
    SqlServer_删除重复行只保留一条记录
    SqlServer_合并多个递归查询数据(CTE)
    rabbitmq_坑
    mongodb_性能监控
  • 原文地址:https://www.cnblogs.com/Judge/p/11619821.html
Copyright © 2011-2022 走看看