思路:SG函数应用!!

代码如下:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
int sg[],n;
vector<int>p[];
int dfs(int now)
{
if(sg[now]!=-) return sg[now];
bool vis[]={};
for(int i=;i<p[now].size();i++)
vis[dfs(p[now][i])]=;
int i=;
while(vis[i]) i++;
return sg[now]=i;
}
int main()
{
int a,b,q,k;
while(scanf("%d",&n)!=EOF){
memset(sg,-,sizeof(sg));
for(int i=;i<n;i++){
scanf("%d",&a);
p[i].clear();
for(int j=;j<a;j++){
scanf("%d",&b);
p[i].push_back(b);
}
}
while(scanf("%d",&q)&&q){
int ans=;
for(int i=;i<q;i++){
scanf("%d",&k);
ans^=dfs(k);
}
puts(ans?"WIN":"LOSE");
}
}
return ;
}

poj 2425 A Chess Game 博弈论的更多相关文章

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

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

  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函数)

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

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

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

  5. poj 2425 A Chess Game_sg函数

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

  6. POJ 2425 A Chess Game(有向图SG函数)题解

    题意:给一个有向图,然后个m颗石头放在图上的几个点上,每次只能移动一步,如果不能移动者败 思路:dfs打表sg函数,然后求异或和 代码: #include<queue> #include& ...

  7. poj 2425 AChessGame(博弈)

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

  8. POJ.1067 取石子游戏 (博弈论 威佐夫博弈)

    POJ.1067 取石子游戏 (博弈论 威佐夫博弈) 题意分析 简单的威佐夫博弈 博弈论快速入门 代码总览 #include <cstdio> #include <cmath> ...

  9. A Chess Game POJ - 2425

    Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesse ...

随机推荐

  1. Spring源码下载

    Spring已经将源码从SVN迁移到了Github,而且也改为基于Gradle的构建来构建项目,它取代了之前的ANT+Ivy系统,所以要构建Spring源码要先安装Github和Gradle. 首先假 ...

  2. Media Player(APP)

    今天共享一下,以前做的影音播放器.比较简单.适合新手. 我上传了附件可以参考一下. PDF:http://files.cnblogs.com/files/hongguang-kim/MediaPlay ...

  3. poj 1985 Cow Marathon

    题目连接 http://poj.org/problem?id=1985 Cow Marathon Description After hearing about the epidemic of obe ...

  4. poj 2153 Rank List

    原题链接:http://poj.org/problem?id=2153 简单题,map,平衡树均可.. map: #include<algorithm> #include<iostr ...

  5. microsoft azure Media Services 媒体服务解决方案

    用安全的方式为您随时随地跨设备传送媒体内容.提供可伸缩的端到端媒体解决方案 可用于高级视频工作流的云 实现奥运会规模的直播与点播媒体传送 高可用的编码和流式处理 支持 Flash.iOS.Androi ...

  6. centos6.5适用的国内yum源:网易、搜狐

    设置方法如下: 1,进入yum源配置目录cd /etc/yum.repos.d 2,备份系统自带的yum源mv CentOS-Base.repo CentOS-Base.repo.bak 下载163网 ...

  7. Filter介绍

    Filter可人为是Servlet的一种“加强版”,它重要用于对用户请求进行预处理,也可以对HttpServletResponse进行后处理,是个典型的处理链.使用Filter的完整的流程是:Filt ...

  8. Unity3d之Mecanim(新版动画系统)

    1,动画系统配置,2,代码控制动画 原文地址:http://blog.csdn.net/dingkun520wy/article/details/51247491 1,动画系统配置 创建Animato ...

  9. Convert Sorted Array to Binary Search Tree

    Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...

  10. Python中数据的保存和读取

    在科学计算的过程中,往往需要保存一些数据,也经常需要把保存的这些数据加载到程序中,在 Matlab 中我们可以用 save 和 lood 函数很方便的实现.类似的在 Python 中,我们可以用 nu ...