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

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. 【HDOJ】1104 Remainder

    bfs. #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> ...

  2. 【HDOJ】1494 跑跑卡丁车

    DP,将能量映射为0~14,注意当选择这圈加速的时候,这圈就不能再储存能量,同时能量14可能转化为10. #include <cstdio> #include <cstring> ...

  3. 多个ajax按照顺序执行的方法

    $.ajax({ dataType: "json", async: false, //只需将此属性设置为false url: ~~, type: "GET", ...

  4. [LeetCode] 200. Number of Islands 解题思路

    Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...

  5. memcached学习——大纲简介 && 安装(基于centos6.5)、启动、关闭memcached(一)

    大纲简介 安装前,先简单介绍一下memcached. memcached是一个免费.开源.高性能的分布式缓存.设计memcached的初衷是为了加快web应用程序,减少DB负载. 安装要求:支持大多数 ...

  6. 如何用SVN进行个人版本管理

    事实上SVN的确是我用过的最好的源码管理工具,虽然我用过的这类工具并不多,只有VSS.CVS和SVN,其它像PVCS. TeamSource.ClearCase之类的只有耳闻,因为它们都是商业产品,并 ...

  7. SpringMVC+highstock实现曲线报表

    最近项目要做曲线报表,之前用的是生成图片然后传到前端,感觉不是很好,在网上找到资料说highstock就可以而且还可以做类似股票的那种实时的曲线,研究的一段时间把项目问题解决了做个总结: 首先把hig ...

  8. 自定义listView添加滑动删除功能

    今天研究了一下android里面的手势,结合昨天学习的自定义View,做了一个自定义的listview,继承自listView,添加了条目的滑动手势操作,滑动后出现一个删除按钮,点击删除按钮,触发一个 ...

  9. UVALive 6525 Attacking rooks 二分匹配 经典题

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4536">点击打开链接 题意: ...

  10. 02-大文件Copy(FileStream文件流类)

    static void Main(string[] args) { string source = @"e:\1.exe";//要移动文件的路径 大文件 string target ...