题意:给一个有向图,然后个m颗石头放在图上的几个点上,每次只能移动一步,如果不能移动者败

思路:dfs打表sg函数,然后求异或和

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define eps 1e-9
typedef long long ll;
const int maxn = + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
vector<int> G[maxn];
int in[maxn], n;
int s[maxn], sg[maxn];
void dfs(int u){
if(G[u].size() == ){
sg[u] = ;
return;
}
for(int i = ; i < G[u].size(); i++){
int v = G[u][i];
if(sg[v] == -)
dfs(v);
}
memset(s, , sizeof(s));
for(int i = ; i < G[u].size(); i++){
int v = G[u][i];
s[sg[v]] = ;
}
for(int i = ; i < maxn; i++){
if(!s[i]){
sg[u] = i;
return;
}
}
}
int main(){
while(~scanf("%d", &n)){
memset(in, , sizeof(in));
memset(sg, -, sizeof(sg));
for(int i = ; i <= n - ; i++){
int x, to;
G[i].clear();
scanf("%d", &x);
while(x--){
scanf("%d", &to);
G[i].push_back(to);
in[to]++;
}
}
for(int i = ; i <= n - ; i++){
if(!in[i]){
dfs(i);
}
}
int m;
while(scanf("%d", &m) && m){
int ans = , x;
while(m--){
scanf("%d", &x);
ans ^= sg[x];
}
if(ans == ) printf("LOSE\n");
else printf("WIN\n");
}
}
return ;
}

POJ 2425 A Chess Game(有向图SG函数)题解的更多相关文章

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

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

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

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

  3. POJ 2425 A Chess Game#树形SG

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

  4. POJ2425 A Chess Game[博弈论 SG函数]

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

  5. poj 2425 A Chess Game 博弈论

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

  6. poj 3575 Crosses and Crosses(SG函数)

    Crosses and Crosses Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3063   Accepted: 11 ...

  7. poj 2425 A Chess Game_sg函数

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

  8. pku 2425 A Chess Game (SG)

    题意: 给一个由N个点组成的一张有向图,不存在环.点的编号是0~N-1. 然后给出M个棋子所在的位置(点的编号)[一个点上可同时有多个棋子]. 每人每次可移动M个棋子中的一个棋子一步,移动方向是有向边 ...

  9. HDU 1524 A Chess Game【SG函数】

    题意:一个N个点的拓扑图,有M个棋子,两个人轮流操作,每次操作可以把一个点的棋子移动到它的一个后继点上(每个点可以放多个棋子),直到不能操作,问先手是否赢. 思路:DFS求每个点的SG值,没有后继的点 ...

随机推荐

  1. Codeforces Round #247 (Div. 2) D. Random Task

    D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. javascript-js模拟form页面提交跳转

    window.location.href跳转到另外一个界面.但直接传递get方法会暴露数据 下面可以实现跳转的效果,却又能够通过post传递方法隐藏数据. 有一个不足就是,在跳转到新页面后,点击“返回 ...

  3. Windows下pycharm使用theano的方法

    安装theano前需要自行安装Anaconda和PyCharm.在网上查了在PyCharm上安装theano的方法,但是均遇到了一些问题,现将问题与解决方案介绍如下. (一)第一种安装方式 打开cmd ...

  4. Andrew Ng-ML-第八章-正则化

    1.过度拟合overfitting 过度拟合,因为有太多的特征+过少的训练数据,学习到的假设可能很适应训练集,但是不能泛化到新的样例.即泛化generalize能力差. 解决办法: 1.手动/使用选择 ...

  5. [LeetCode] 200. Number of Islands_ Medium tag: BFS

    Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...

  6. python -- 解决If using all scalar values, you must pass an index问题

    [问题描述] 在将dict转为DataFrame时会报错:If using all scalar values, you must pass an index 例如: summary = pd.Dat ...

  7. android开发中遇到的一些问题

    buildToolsVersion 设置buildtool版本 今天遇到一个奇怪问题instant not supported 原来是设置显示offline...这个很无语,adb devices又能 ...

  8. unity3d-物理引擎

    简介 物理引擎就是在游戏中模拟真实的物理效果,比如,场景中有两个立方体对象,一个在空中,一个在地面上,在空中的立方体开始自由下落,然后与地面上的立方体对象发生碰撞,而物理引擎就是用来模拟真实碰撞的效果 ...

  9. BP神经网络原理详解

    转自博客园@编程De: http://www.cnblogs.com/jzhlin/archive/2012/07/28/bp.html  http://blog.sina.com.cn/s/blog ...

  10. sql when null 判断

    Sql Server 中使用case when then 判断某字段是否为null,和判断是否为字符或数字时的写法不一样,如果不注意,很容易搞错 错误方法: CASE columnName WHEN ...