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

Description

Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesses can be located in the same position. The positions are constituted as a topological graph, i.e. there are directed edges connecting some positions, and no cycle exists. Two players you and I move chesses alternately. In each turn the player should move only one chess from the current position to one of its out-positions along an edge. The game does not end, until one of the players cannot move chess any more. If you cannot move any chess in your turn, you lose. Otherwise, if the misfortune falls on me... I will disturb the chesses and play it again.

Do you want to challenge me? Just write your program to show your qualification!

Input

Input contains multiple test cases. Each test case starts with a number N (1 <= N <= 1000) in one line. Then the following N lines describe the out-positions of each position. Each line starts with an integer Xi that is the number of out-positions for the position i. Then Xi integers following specify the out-positions. Positions are indexed from 0 to N-1. Then multiple queries follow. Each query occupies only one line. The line starts with a number M (1 <= M <= 10), and then come M integers, which are the initial positions of chesses. A line with number 0 ends the test case.

Output

There is one line for each query, which contains a string "WIN" or "LOSE". "WIN" means that the player taking the first turn can win the game according to a clever strategy; otherwise "LOSE" should be printed.

Sample Input

4
2 1 2
0
1 3
0
1 0
2 0 2
0 4
1 1
1 2
0
0
2 0 1
2 1 1
3 0 1 3
0

Sample Output

WIN
WIN
WIN
LOSE
WIN

Hint

Huge input,scanf is recommended.

Source

PKU Monthly,CHEN Shixi(xreborner)

裸SG函数搜索
注意used不能共用一个
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1e3+,INF=1e9;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,s,v;
struct edge{
int v,w,ne;
}e[N*N];
int h[N],cnt=;
void ins(int u,int v){
cnt++;
e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
}
int sg[N];
int dfs(int u){
if(sg[u]!=-) return sg[u];
bool used[N];
memset(used,,sizeof(used));
for(int i=h[u];i;i=e[i].ne) used[dfs(e[i].v)]=;
for(int i=;;i++) if(!used[i]) {sg[u]=i;break;}
return sg[u];
}
int main(){
while(scanf("%d",&n)!=EOF){
memset(sg,-,sizeof(sg));
memset(h,,sizeof(h));
cnt=;
for(int i=;i<=n;i++){
s=read();
while(s--) ins(i,read()+);
}
while((s=read())){
int ans=;
for(int i=;i<=s;i++) ans^=dfs(read()+);
if(ans) puts("WIN");
else puts("LOSE");
}
}
}
 
 

POJ2425 A Chess Game[博弈论 SG函数]的更多相关文章

  1. POJ 2425 A Chess Game 博弈论 sg函数

    http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...

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

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

  3. 2016多校联合训练1 B题Chess (博弈论 SG函数)

    题目大意:一个n(n<=1000)行,20列的棋盘上有一些棋子,两个人下棋,每回合可以把任意一个棋子向右移动到这一行的离这个棋子最近的空格上(注意这里不一定是移动最后一个棋子),不能移动到棋盘外 ...

  4. poj 2425 A Chess Game(SG函数)

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

  5. 【基础操作】博弈论 / SG 函数详解

    博弈死我了……(话说哪个小学生会玩博弈论提到的这类弱智游戏,还取石子) 先推荐两个文章链接:浅谈算法——博弈论(从零开始的博弈论) 博弈论相关知识及其应用 This article was updat ...

  6. bzoj1188 [HNOI2007]分裂游戏 博弈论 sg函数的应用

    1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 973  Solved: 599[Submit][Status ...

  7. [BZOJ 1188] [HNOI2007] 分裂游戏 【博弈论|SG函数】

    题目链接:BZOJ - 1188 题目分析 我们把每一颗石子看做一个单个的游戏,它的 SG 值取决于它的位置. 对于一颗在 i 位置的石子,根据游戏规则,它的后继状态就是枚举符合条件的 j, k.然后 ...

  8. [BZOJ 1874] [BeiJing2009 WinterCamp] 取石子游戏 【博弈论 | SG函数】

    题目链接:BZOJ - 1874 题目分析 这个是一种组合游戏,是许多单个SG游戏的和. 就是指,总的游戏由许多单个SG游戏组合而成,每个SG游戏(也就是每一堆石子)之间互不干扰,每次从所有的单个游戏 ...

  9. 【GZOI2015】石子游戏 博弈论 SG函数

    题目大意 有\(n\)堆石子,两个人可以轮流取石子.每次可以选择一堆石子,做出下列的其中一点操作: 1.移去整堆石子 2.设石子堆中有\(x\)个石子,取出\(y\)堆石子,其中\(1\leq y&l ...

随机推荐

  1. Visual Studio 2015在.NET Core RC2项目中的一个错误。

    更新了.NET Core RC2 之后,VS的Web Tools更新为“Preview 1”了. 这个版本有一个问题,害我折腾了一个下午. 就是在项目界面的“依赖项 - NPM”上面错误地显示了不必要 ...

  2. javascript严格模式

    设立"严格模式"的目的,主要有以下几个: 1. 消除Javascript语法的一些不合理.不严谨之处,减少一些怪异行为; 2. 消除代码运行的一些不安全之处,保证代码运行的安全: ...

  3. java protected 的细节

    1. java的权限控制--大部分人都被错误洗脑了. 一个重大的坑,或者一个重大的误区,或者说一个洗脑了成千上万java编程者的错误概念就是: public private protected 是基于 ...

  4. powershell脚本,命令行参数传值,并绑定变量的例子

    这是小技巧文章,所以文章不长.但原创唯一,非常重要.我搜了下,还真没有人发 powershell怎样 [命令行 参数 绑定],所以我决定写成博客. 搜索关键字如下: powershell 命令行 参数 ...

  5. 【系统架构】IT职业技能图谱(点开大图查看)

    本文地址 1 程序开发语言综述 2 iOS开发工程师必备技能 3 运维工程师必备技能 4 前端工程师必备技能 5 大数据工程师必备技能 6 云计算工程师必备技能 7 安全工程师必备技能 8 移动无线测 ...

  6. DecoratorPattern(装饰器模式)

    /** * 装饰者模式 * @author TMAC-J * 总的来说,装饰者模式就是继承的应用 */ public class DecoratorPattern { interface Beans{ ...

  7. 帆布指纹识别(canvas fingerprinting)

    广告联盟或许网站运营者都希望能够精准定位并标识每一个个体,通过对用户行为的分析(浏览了哪些页面?搜索了哪些关键字?对什么感兴趣?点了哪些按钮?用了哪些功能?看了哪些商品?把哪些放入了购物车等等),为用 ...

  8. S2---深入.NET平台和C#编程的完美总结

    1.NET简单解说 l 面向对象提升 OOP(Object Oriented  Programming)面向对象编程 AOP:(Aspache  Oriented Programming):面向切面编 ...

  9. 20个编写现代 CSS 代码的建议

    明白何谓Margin Collapse 不同于其他很多属性,盒模型中垂直方向上的Margin会在相遇时发生崩塌,也就是说当某个元素的底部Margin与另一个元素的顶部Margin相邻时,只有二者中的较 ...

  10. Managing database evolutions

    When you use a relational database, you need a way to track and organize your database schema evolut ...