题意:给定一棵有向图的树,有些节点上有石子,每次可以取一个石子向一个有向边移动,不能移动者负。

Ans:树上nim,叶子节点nim为0,父亲节点递归儿子得到sg值,答案就是每个石子所在点的sg值异或和。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
int sg[],s[],n,x,ans,m;
int tot,go[*],first[],next[*],ru[],num;
void insert(int x,int y){
tot++;
go[tot]=y;
next[tot]=first[x];
first[x]=tot;
}
int dfs(int x){
if (s[x]!=-) return s[x];
//if (first[x]==0) return s[x]=0;
int ss[];
memset(ss,,sizeof ss);
for (int i=first[x];i;i=next[i]){
int pur=go[i];
ss[dfs(pur)]=;
}
for (int i=;i<=n+;i++)
if (ss[i]==) return s[x]=i;
}
int main(){
freopen("tx.in","r",stdin);
while (~scanf("%d",&n)){
memset(s,-,sizeof s);
memset(first,,sizeof first);
memset(ru,,sizeof ru);
tot=;
for (int i=;i<n;i++){
scanf("%d",&num);
for (int j=;j<=num;j++){
scanf("%d",&x);
insert(i,x);
ru[x]++;
}
}
for (int i=;i<n;i++)
if (ru[i]==){
s[i]=dfs(i);
}
while (scanf("%d",&m)&&m){
ans=;
for (int i=;i<=m;i++){
scanf("%d",&x);
ans^=s[x];
}
if (ans) printf("WIN\n");
else printf("LOSE\n");
}
}
}

poj2425--A Chess Game的更多相关文章

  1. [poj2425]A Chess Game_博弈论

    A Chess Game poj-2425 题目大意:题目链接 注释:略. 想法:这个题就是为什么必须要用记忆化搜索.因为压根就不知道后继是谁. 我们通过SG定理可知:当前游戏的SG值等于所有子游戏的 ...

  2. POJ2425 A Chess Game[博弈论 SG函数]

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Desc ...

  3. POJ2425 A Chess Game(SG函数+记忆化深搜)

    题目链接:传送门 题目大意: 在一个有N个点的拓扑图上(拓扑图以邻接表的形式输入),放M个棋子(棋子与棋子之间无关,可以重合). 两人轮流移动棋子,每次只能移动一个棋子经过一条边. 问先手是否必胜. ...

  4. 博弈问题之SG函数博弈小结

    SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...

  5. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  6. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

  7. hdu4405 Aeroplane chess

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. HDU 5742 Chess SG函数博弈

    Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. ...

  9. HDU 4832 Chess (DP)

    Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  10. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

随机推荐

  1. alias, bg, bind, break, builtin, caller, cd, command,

    bash,  :,  .,  [, alias, bg, bind, break, builtin, caller, cd, command,       compgen, complete, com ...

  2. BZOJ1119: [POI2009]SLO

    1119: [POI2009]SLO Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 379  Solved: 181[Submit][Status] ...

  3. Apache-common项目提供的工具

    ---- MD5加密与生成UUID例子(依赖于commons-io.jar):begin ------------------------------------------------------- ...

  4. 聚聚科技---PHP开发笔试题及答案

    1. echo(), print(), print_r()的区别? echo是PHP语言结构, print和print_r是函数.语言结构没有返回值,函数可以有返回值(即便没有用)  . print( ...

  5. 转载:mybatis和hibernate 解析

    第一章     Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀 ...

  6. 【iOS基础】iOS 线程相关技术

    零.线程的注意点(掌握)1.不要同时开太多的线程(1~3条线程即可,不要超过5条)2.线程概念1> 主线程 : UI线程,显示.刷新UI界面,处理UI控件的事件2> 子线程 : 后台线程, ...

  7. DLNA介绍(包含UPnP,2011/6/20 更新)

    这部分的内容大多来源于网络及官方文档,依照自己的翻译理解整理所成.东西比較多,从头慢慢看还是能够懂个大概的. 文件夹: 一.DNLA的建立 二.DLNA的成员 三.DLNA标准的制定 四.DLNA的设 ...

  8. Tomcat全攻略

    内容: 一:简单介绍 二:安装及配置 三:应用 四:综述 參考资料 关于作者 相关内容: TCP/IP 介绍 TCP/IP 介绍 !== End Related dW Content Area --& ...

  9. windows下php+apache+mysql环境搭建

    在Windows 7下进行PHP环境搭建,首先需要下载PHP代码包和Apache与Mysql的安装软件包. PHP版本:php-5.3.2-Win32-VC6-x86,VC9是专门为IIS定制的,VC ...

  10. memcached原理全面剖析

    memcached会预先分配内存,memcached分配内存方式称之为allocator, 首先,这里有3个概念: 1 slab 2 page 3 chunk 一般来说一个memcahced进程会预先 ...