poj2425--A Chess Game
题意:给定一棵有向图的树,有些节点上有石子,每次可以取一个石子向一个有向边移动,不能移动者负。
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的更多相关文章
- [poj2425]A Chess Game_博弈论
A Chess Game poj-2425 题目大意:题目链接 注释:略. 想法:这个题就是为什么必须要用记忆化搜索.因为压根就不知道后继是谁. 我们通过SG定理可知:当前游戏的SG值等于所有子游戏的 ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
- POJ2425 A Chess Game(SG函数+记忆化深搜)
题目链接:传送门 题目大意: 在一个有N个点的拓扑图上(拓扑图以邻接表的形式输入),放M个棋子(棋子与棋子之间无关,可以重合). 两人轮流移动棋子,每次只能移动一个棋子经过一条边. 问先手是否必胜. ...
- 博弈问题之SG函数博弈小结
SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...
- 博弈论BOSS
基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...
- 【Mark】博弈类题目小结(HDU,POJ,ZOJ)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...
- hdu4405 Aeroplane chess
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 5742 Chess SG函数博弈
Chess Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. ...
- HDU 4832 Chess (DP)
Chess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
随机推荐
- 【HDOJ】4515 小Q系列故事——世界上最遥远的距离
简单题目,先把时间都归到整年,然后再计算.同时为了防止减法出现xx月00日的情况,需要将d先多增加1,再恢复回来. #include <cstdio> #include <cstri ...
- 设计模式 ( 十七 ):Observer 观察者模式 -- 行为型
1.概述 一些面向对象的编程方式,提供了一种构建对象间复杂网络互连的能力.当对象们连接在一起时,它们就可以相互提供服务和信息. 通常来说,当某个对象的状态发生改变时,你仍然需要对象之间能互相通信.但是 ...
- 高德JAVA笔试题
1.常用的RuntimeException. 2.叙述RuntimeException和一般异常的异同. 3.叙述ArrayList.Vector和LinkedList各自的特点和特性. 4.什么是反 ...
- LIS 最长单调子序列模板
namespace LIS { template <class T> int lis(vector<T> v) { ; vector<T> d; ;i<v.s ...
- 常用cl命令参数解释
紧接前文,第一行cl命令如下: 1> cl /c /IC:\...\include /ZI /nologo- /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG ...
- JS点击按钮弹出窗口
由于没有系统学习过JS,遇到一个需求:点击按钮,弹出一个独立的窗口. 在网上百度了一下,并没有找到满意的结果,最重要的是各种方法很复杂.最终,仔细研究了一下,原来只是需要只要一个简单的函数就能满足自己 ...
- Objective-C基础学习笔记——对象初始化
obj中创建新对象有两种方式:[classname new]和[[classname alloc] init].两种方法等价,Cocoa惯例是使用alloc和init. 1.分配对象: allocat ...
- Mac phpstorm破解版安装(简单,有效)
如果是公司作为商业用途的,还是希望你能购买正版的,如果是苦逼的穷学生,亦或是我这样的苦逼码农,那就往下看, 之前有个只需要在"License server address"里输入 ...
- J2EE基础总结(4)——JSP
什么是JSP JSP全名为Java Server Pages,中文名叫javaserver页面,其根本是一个简化的Servlet设计,它是由Sun Microsystems公司倡导.很多 ...
- java\C#\php主流语言实现FMS流媒体传输协议RTMP的开源组件
java:bladeDS http://sourceforge.net/adobe/blazeds/wiki/Home/ .net:FlourinceFX http://www.fluorinefx. ...