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 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...
随机推荐
- cacti启动有图无数据
cactiEZ服务器重启后,获取不到图形的解决办法 cd /var/www/html/cli/ php -q rebuild_poller_cache.php -d myisamchk --safe- ...
- python数据字典的操作
一.什么是字典? 字典是Python语言中唯一的映射类型. 映射类型对象里哈希值(键,key)和指向的对象(值,value)是一对多的的关系,通常被认为是可变的哈希表. 字典对象是可变的,它是一个容器 ...
- grep家族
grep家族由命令grep.egrep和fgrep组成. grep:在文件中全局查找指定的正则表达式,并且打印所有包含该表达式的行.egrep和fgrep是grep的变体.egrep:grep的扩展, ...
- sql数据库各个版本清除日志
SQL2005清空删除日志: 复制代码 代码如下: Backup Log DNName with no_log --'这里的DNName是你要收缩的数据库名,自己注意修改下面的数据 ...
- FastDFS介绍和配置过程 二
最近在研究负载均衡和集群,其中涉及到一个主要问题是,如何让集群中的real server共享一套文件系统.在网上查到FastDFS,国人(happy fish,感谢他的开源精神)开发的一套轻量级分 ...
- 【总结整理】KANO 模型
c 基本(必备)型需求——Must-beQuality/ Basic Quality. 期望(意愿)型需求——One-dimensional Quality/ Performance Quality. ...
- 50. Pow(x, n) 幂次方
[抄题]: mplement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, ...
- 118. Pascal's Triangle杨辉三角形(全部/一行)
[抄题]: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- Solidity oraclize 常用数据源
1. 股票数据: https://blog.quandl.com/api-for-stock-data iextrading.com www.nowapi.com 中文 2. 外汇数据: https: ...
- 如何看待那些不能重现的bug?
在我们日常测试活动中,经常会发现一些bug,但是这些bug可能就是昙花一现,再也无法(或者很难)重现出来,内心灰常崩溃.那到底有哪些方面可能会导致这类的缺陷发生呢? 我以自己工作中所遇到的给出一些自己 ...