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. 需求分析&原型设计

    需求分析&原型设计 需求分析 访问软件项目真实用户 首先本项目的用户是这个需要做简单四则运算的用户(我们团队通过对家里有三四年级小学生(需要做简单四则运算)的简单采访):反映了几个主要的问题: ...

  2. 微信小程序测试总结

    概述 由于项目中,微信前端和后端对接出现错误.所以Alpha测试分为微信小程序前端,管理员web测试. 测试工具选择 微信小程序的前端使用微信小程序开发工具测试. 管理员web使用web测试. 测试工 ...

  3. xcode修改代码目录结构出现clang:error:nosuchfileordirectory解决方法

    需要迁移一个开源工程的一部分内容到自己工程,迁移对方的工程到自己工程之后,因目录结构配置整理需要,对嵌入的工程目录进行了结构改变,编译后出现: clang: error: no such file o ...

  4. SQL的介绍及MySQL的安装

    基础篇 - SQL 介绍及 MySQL 安装               SQL的介绍及MySQL的安装 课程介绍 本课程为实验楼提供的 MySQL 实验教程,所有的步骤都在实验楼在线实验环境中完成, ...

  5. JAVA_SE基础——9.基本数据类型间的转换

    前面我已经教会大家基本的数据类型进行了介绍,   然后这篇文章,我来介绍下,基本数据类型的转换. Java中有两种类型转换形式,分别是自动类型转换和强制类型转换. Step1.自动类型转换. 自动类型 ...

  6. Highcharts tooltip显示多条线的信息

    直接上代码吧,简单粗暴点: tooltip: { shared: true, valueSuffix: '分', formatter: function () { let s = "&quo ...

  7. Linux CentOS7.0 (04)systemctl vs chkconfig、service

    CentOS 7.0中已经没有service命令,而是启用了systemctl服务器命令 systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到 ...

  8. hadoop2.7.3+spark2.1.0+scala2.12.1环境搭建(4)SPARK 安装

    hadoop2.7.3+spark2.1.0+scala2.12.1环境搭建(4)SPARK 安装 一.依赖文件安装 1.1 JDK 参见博文:http://www.cnblogs.com/liugh ...

  9. maven入门(10)maven的仓库

    [0]README 1)本文部分文字转自 "maven实战",旨在 review  "maven(6)仓库" 的相关知识:   [1]何为 Maven仓库 1) ...

  10. Python进程

    (先分享一个Python在线编程的网站http://www.pythontip.com/coding/skulpt-interactive/) (本文为原创作品,欢迎转载,转载请注明出处) 一.概念 ...