HDU - 5996 树上博弈 BestCoder Round #90

就是阶梯NIM博弈,那么看层数是不是奇数的异或就行了;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 400005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-11
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/
int T;
vector<int>vc[maxn];
int ans;
int a[maxn];
void dfs(int u,int fa,int dep){
for(int i=0;i<vc[u].size();i++){
int v=vc[u][i];
if((dep+1)%2)ans^=a[v];
dfs(v,u,dep+1);
}
}
int main() {
T=rd();
while(T--){
int n;rdint(n);
for(int i=0;i<=n;i++)vc[i].clear();
for(int i=1;i<n;i++){
int fa;rdint(fa);
vc[fa].push_back(i);
}
ans=0;
for(int i=0;i<n;i++)rdint(a[i]);
dfs(0,0,0);
if(ans)cout<<"win"<<endl;
else cout<<"lose"<<endl;
}
}
HDU - 5996 树上博弈 BestCoder Round #90的更多相关文章
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
- BestCoder Round #90 A+B题解!
BestCoder Round #90 A Kblack loves flag 题意有点迷不造思路很简单但不造怎么求随机数,纠结了一会后直接粘上题目所给的代码稍加修改A了. const int _K ...
- HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...
- hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 5996 dingyeye loves stone ---BestCoder Round #90
题目链接 设根节点的深度为0,将所有深度为奇数的节点的石子数目xor起来,则先手必胜当且仅当这个xor和不为0. 证明同阶梯博弈.对于偶深度的点上的石子,若对手移动它们,则可模仿操作:对于奇深度上的石 ...
- HDU 5995 Kblack loves flag ---BestCoder Round #90
题目链接 用两个布尔数组分别维护每个行/列是否被插过旗帜,最后枚举每一行.列统计答案即可.空间复杂度O(n+m),时间复杂度O(n+m+k). #include <cstdio> #inc ...
- BestCoder Round #90
有生以来第一场在COGS以外的地方打的比赛.挂成dog了. 主要是没有经验,加之代码能力过弱.还有最后的瞎hack三次,Too Young Too Simple...... 言归正传. (抄一发题解先 ...
- BestCoder Round #90 A.Kblack loves flag(随机数生成种子)
A.Kblack loves flag [题目链接]A.Kblack loves flag [题目类型]水题 &题意: kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,k ...
- HDU 5904 - LCIS (BestCoder Round #87)
HDU 5904 - LCIS [ DP ] BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...
随机推荐
- shelve和hashlib模块
一.shelve模块 shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式. 注意: shelve模块封装了pickle模块,,允许 ...
- 不要向没权力&能力的人证明自己的能力
[不要向没权力&能力的人证明自己的能力] 不是所有的上级都有足够的权力和能力.一个没权力的Leader,即使你向他证明了自己的能力,你所能获得的也只能是他的邮件表扬的荣誉.对于加薪,他能给的仅 ...
- 1 JPA入门----项目搭建以及CRUD
maven搭建JPA开发环境 1 依赖的maven pom文件 主要有hibernate-core.hibernate-entitymanager.javax-persistence.mysq ...
- selenium3加载浏览器
浏览器禁用更新: 因为selenium对浏览器的支持是有限制的.当浏览器更新到最新版本时,需要下载支持最新版本的插件.有时候selenium还没有更新到支持最新版本的插件,但本地已经更新到最新版本了. ...
- <c:out>标签中有一个escapeXml属性 如果为escapeXml="false",则将其中的html、xml解析出来。
<td><c:out value="${s.name}" escapeXml="false"></c:out></td ...
- 调用req.getParameter方法出现中文乱码(全是问号???)
在java开发中,如果编码配置不统一,很容易出现中文乱码的情况,这里就记录下自己遇到的调用req.getParameter方法出现中文乱码,并解决这一情况的方法 注意修改以下几个地方 1.jsp页面中 ...
- 23、sed常用命令
1.匹配与不匹配: n p ! sed -n '/ATTGC/p' file1 ##-n打印匹配到的行输出,默认所有行输出. sed -n '/AT\|GC/p' fil ...
- php变量数据类型
整型:可以用十进制.八进制.十六进制指定.十进制就是日常使用的数字:八进制,数字前必须加上“0”(这个0是阿拉伯数字0,可不是英文字母“欧”哦):十六进制,数字前必须加“0x” (这个0也是阿拉伯数字 ...
- App测试从入门到精通之兼容性和回归测试
兼容性测试需要考虑的APP测试点 1.不同网络环境下的兼容性测试 2.不同手机操作系统兼容性测试 3.不同应用软件的兼容性测试 4.不同的容量大小的SIM卡之间的互相兼容测试 5.当安装杀毒软件时,应 ...
- linux 的各个文件夹都是干什么用
http://www.ruanyifeng.com/blog/2012/02/a_history_of_unix_directory_structure.html http://www.pathnam ...