A Chess Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1100    Accepted Submission(s): 504

Problem 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

用SG函数做的:

 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
#define ll long long int
vector<int> a[];
int z[];
int n;
int dfs(int x)
{
if(z[x]!=-)return z[x];
int size=a[x].size();
int i;
int c[n];
memset(c,,sizeof(c));
for(i=;i<size;i++)
{
c[dfs(a[x][i])]=;
}
for(i=;i<n;i++)
if(!c[i])
{
z[x]=i;
break;
}
return z[x];
}
int main()
{
while(cin>>n)
{
bool b[n];
memset(z,-,sizeof(z));
memset(b,,sizeof(b));
int i,j,m,x;
for(i=;i<n;i++)
{
a[i].clear();
cin>>m;
for(j=;j<m;j++)
{
cin>>x;
a[i].push_back(x);
b[x]=;
}
}
for(i=;i<n;i++)
{
if(!b[i])
dfs(i);
}
while(cin>>m&&m)
{
int sum=;
for(i=;i<m;i++)
{
cin>>x;
sum^=z[x];
}
if(sum)
cout<<"WIN"<<endl;
else cout<<"LOSE"<<endl;
}
}
}

hdu1524博弈SG的更多相关文章

  1. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  2. 博弈SG

    先转一篇看得比较懂的,以后有时间自己再归纳下 转自:http://blog.csdn.net/logic_nut/article/details/4711489 博弈问题若你想仔细学习博弈论,我强烈推 ...

  3. BZOJ-1228 E&D 博弈SG+找啊找啊找规律

    讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solv ...

  4. hdu 3032(博弈sg函数)

    题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...

  5. HDU-4678 Mine 博弈SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...

  6. (博弈 sg入门2)

    接下来介绍Nim游戏(同样引用杭电上的,懒的打字) 1.有两个玩家:   2.  有三堆扑克牌(比如:可以分别是    5,7,9张):  3. 游戏双方轮流操作:  4. 玩家的每次操作是选择其中某 ...

  7. (转)博弈 SG函数

    此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...

  8. 尼姆博弈+SG函数

    博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...

  9. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

随机推荐

  1. hashMap遍历方式

    package Ch17; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java ...

  2. Grails笔记四:Groovy特性小结

    在学习Grails的时候与Groovy打交道不可避免,虽然不必太深刻,但多知道一些特性也是很有帮助的~ 1.相除后获取整数 使用intdiv()方法可以获得整数,注意点是这个方法只适用两个整数相除,浮 ...

  3. keepalive之LVS-DR架构

    author:JevonWei 版权声明:原创作品 Keepalive实战之LVS-DR 实验目的:构建LVS-DR架构,为了达到LVS的高可用目的,故在LVS-DR的Director端做Keepal ...

  4. Javascript的内容摘要

    JS简介和变量 {JS的三种方式}            1 HTML中内嵌JS(不提倡使用)            <button onclick="javascript:alert ...

  5. IT团队之非正式沟通

      沟通能力是一种能证明和让对方发现你具有社会工作能力的能力.从表面上看来,它只是一种能说会道的能力,可实际上它却包罗了一个人从穿衣打扮到言谈举止等一切行为的能力.   从大体上,我将沟通分为正式沟通 ...

  6. java基础解析系列(五)---HashMap并发下的问题以及HashTable和CurrentHashMap的区别

    java基础解析系列(五)---HashMap并发下的问题以及HashTable和CurrentHashMap的区别 目录 java基础解析系列(一)---String.StringBuffer.St ...

  7. webStrom支持Vue

    找到webstorm-->preferences-->fileTypes-->html-->添加+-->*.vue

  8. 基于NIOS-II的示波器:PART3 初步功能实现

    本文记录了在NIOS II上实现示波器的第三部分. 本文主要包括:硬件部分的BRAM记录波形,计算频率的模块,以及软件部分这两个模块的驱动. 本文所有的硬件以及工程参考来自魏坤示波仪,重新实现驱动并重 ...

  9. AT&T汇编语言学习:利用c库、文件读写

    AT&T汇编.调用C库函数.读/写文件 d0321:更新读文件代码(图片)以后会更新代码版. d0329:汇编文本读取.简单动画. ============================== ...

  10. Java Collections 源码分析

    Java Collections API源码分析 侯捷老师剖析了不少Framework,如MFC,STL等.侯老师有句名言: 源码面前,了无秘密 这句话还在知乎引起广泛讨论. 我对教授程序设计的一点想 ...