A Chess Game
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 3791   Accepted: 1549

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
/*
poj 2425 AChessGame(博弈) 给你一个有向的图,上面的棋子可以移动到下一个节点,如果当前无法移动则失败 可以同dfs求出所有节点的sg值,然后进行计算即可 hhh-2016-08-02 16:50:29 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 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
typedef long long ll;
#define lson (i<<1)
#define rson ((i<<1)|1)
using namespace std; const int maxn = 1000+10; int sg[maxn];
int Map[maxn][maxn];
int n;
void dfs(int now)
{
int vis[maxn] = {0};
for(int i = 0; i < n; i++)
{
if(Map[now][i])
{
if(sg[i] == -1)
dfs(i);
vis[sg[i]] = 1;
} }
for(int i = 0; i < n; i++)
{
if(!vis[i])
{
sg[now] = i;
break;
}
}
} int main()
{
int x,m;
while(scanf("%d",&n) != EOF && n)
{
memset(sg,-1,sizeof(sg));
memset(Map,0,sizeof(Map));
for(int i = 0; i < n; i++)
{
scanf("%d",&m);
for(int j = 1; j <= m; j++)
{
scanf("%d",&x);
Map[i][x] = 1;
}
}
for(int i = 0; i < n; i++)
{
if(sg[i] == -1)
dfs(i);
}
while(scanf("%d",&m)!=EOF && m)
{
int ans = 0;
for(int i = 0; i < m; i++)
{
scanf("%d",&x);
ans ^= sg[x];
}
if(ans)
printf("WIN\n");
else
printf("LOSE\n");
}
}
return 0;
}

  

poj 2425 AChessGame(博弈)的更多相关文章

  1. poj 1704 阶梯博弈

    转自http://blog.sina.com.cn/s/blog_63e4cf2f0100tq4i.html 今天在POJ做了一道博弈题..进而了解到了阶梯博弈...下面阐述一下我对于阶梯博弈的理解. ...

  2. POJ 2425 A Chess Game#树形SG

    http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring&g ...

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

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

  4. POJ 2960 S-Nim<博弈>

    链接:http://poj.org/problem?id=2960 #include<stdio.h> #include<string.h> ; ; int SG[N];//S ...

  5. poj 2425 A Chess Game_sg函数

    题意:给你一个有向无环图,再给你图上的棋子,每人每次只能移动一个棋子,当轮到你不能移动棋子是就输了,棋子可以同时在一个点 比赛时就差这题没ak,做了几天博弈终于搞懂了. #include <io ...

  6. POJ 2234 Nim博弈

    思路: nim博弈裸题 xor一下 //By SiriusRen #include <cstdio> using namespace std; int n,tmp,xx; int main ...

  7. poj 2425 A Chess Game 博弈论

    思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include< ...

  8. [原博客] POJ 2425 A Chess Game

    题目链接题意:给定一个有向无环图(DAG),上面放有一些旗子,旗子可以重合,两个人轮流操作,每次可以把一个旗子从一个位置移动到相邻的位置,无法移动时输,询问先手是否必胜. 这道题可以把每个旗子看作单独 ...

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

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

随机推荐

  1. Webview之H5页面调用android的图库及文件管理

    h5页面打开图片管理器 一般页面在pc打开文件管理器是用 type="file"的代码,可是这在android的webview是无效的,必须为webview设定WebChromeC ...

  2. Android Notification setLatestEventInfo方法已废弃

    代替setLatestEventInfo的方法是用Notification.Builder创建Builder对象,通过该对象设置Notification相关属性. otification.Builde ...

  3. Node.js系列文章:编写自己的命令行界面程序(CLI)

    CLI的全称是Command-line Interface(命令行界面),即在命令行接受用户的键盘输入并作出响应和执行的程序. 在Node.js中,全局安装的包一般都具有命令行界面的功能,例如我们用于 ...

  4. CentOS 7 安装Graphite

    Graphite简介 Graphite是一个Python编写的企业级开源监控工具,采用django框架,用来收集服务器所有的即时状态,用户请求信息,Memcached命中率,RabbitMQ消息服务器 ...

  5. 根据抽象工厂实现的DBHelpers类

    public abstract class DBHelper { public static SqlConnection conn = new SqlConnection("server=l ...

  6. JAVA_SE基础——29.构造函数

    黑马程序员入学Blog... jvm创建Java对象时候需要调用构造器,默认是不带参数的.在构造器中,你可以让jvm帮你初始化一些参数或者执行一系列的动作. 它是对象创建中执行的函数,及第一个被执行的 ...

  7. Linux知识积累(6) 系统目录及其用途

    linux系统常见的重要目录以及各个目作用:/ 根目录.包含了几乎所有的文件目录.相当于中央系统.进入的最简单方法是:cd /./boot引导程序,内核等存放的目录.这个目录,包括了在引导过程中所必需 ...

  8. 您的 Java 代码安全吗 — 还是暴露在外? 【转】

    在开发 Java Web 应用程序时,您需要确保应用程序拥有完善的安全性特征补充.这里在谈到 Java 安全性时,我们并不谈及 Java 语言提供的安全性 API,也不涉及使用 Java 代码来保护应 ...

  9. 框架学习笔记之Hibernate

    一.什么是Hibernate Hibernate框架是当今主流的持久层框架之一,该框架是基于JDBC的主流持久化框架,使用它之后能够大大简化程序DAO层的代码量,提高工作效率,因此受广大开发人员的喜爱 ...

  10. Tensorflow计算模型 —— 计算图

    转载自:http://blog.csdn.net/john_xyz/article/details/69053626 Tensorflow是一个通过计算图的形式来表述计算的编程系统,计算图也叫数据流图 ...