A Chess Game POJ - 2425
Do you want to challenge me? Just write your program to show your qualification!
Input
Output
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
思路:树上nim,叶子节点nim为0,父亲节点递归儿子得到sg值,答案就是每个石子所在点的sg值异或和。
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int mp[][];
int SG[];
int N;
int DFS(int n)
{
int i;
if(SG[n]!=-)
return SG[n];
bool next[];
memset(next, , sizeof(next));
for(i = ; i < N; ++i)
{
if(mp[n][i] != -)
next[DFS(i)] = ;
}
i = ;
while(next[i])
i++;
return SG[n] = i;
}
int main()
{
int i, j, k, t;
int X;
int tp, ans;
while(scanf("%d", &N)!=EOF)
{
memset(mp, -, sizeof(mp));
memset(SG, -, sizeof(SG));
for(i = ; i < N; ++i)
{
scanf("%d", &k);
if(k==) SG[i] = ;
for(j = ; j < k; ++j)
{
scanf("%d", &t);
mp[i][t] = ;
}
}
while(scanf("%d", &X))
{
if(X==) break;
ans = ;
for(i = ; i < X; ++i)
{
scanf("%d", &tp);
ans = ans ^ DFS(tp);
}
if(ans) printf("WIN\n");
else printf("LOSE\n");
}
}
return ;
}
转载
A Chess Game POJ - 2425的更多相关文章
- poj 2425 AChessGame(博弈)
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3791 Accepted: 1549 Desc ...
- POJ 2425 A Chess Game#树形SG
http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring&g ...
- POJ 2425 A Chess Game 博弈论 sg函数
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...
- poj 2425 A Chess Game(SG函数)
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3551 Accepted: 1440 Desc ...
- poj 2425 A Chess Game 博弈论
思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include< ...
- [原博客] POJ 2425 A Chess Game
题目链接题意:给定一个有向无环图(DAG),上面放有一些旗子,旗子可以重合,两个人轮流操作,每次可以把一个旗子从一个位置移动到相邻的位置,无法移动时输,询问先手是否必胜. 这道题可以把每个旗子看作单独 ...
- poj 2425 A Chess Game_sg函数
题意:给你一个有向无环图,再给你图上的棋子,每人每次只能移动一个棋子,当轮到你不能移动棋子是就输了,棋子可以同时在一个点 比赛时就差这题没ak,做了几天博弈终于搞懂了. #include <io ...
- POJ 2425 A Chess Game(有向图SG函数)题解
题意:给一个有向图,然后个m颗石头放在图上的几个点上,每次只能移动一步,如果不能移动者败 思路:dfs打表sg函数,然后求异或和 代码: #include<queue> #include& ...
- SG函数和SG定理【详解】
在介绍SG函数和SG定理之前我们先介绍介绍必胜点与必败点吧. 必胜点和必败点的概念: P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败. N点:必胜点 ...
随机推荐
- Ubuntu 18.04 修改gedit的配色方案
下图中的蓝色的注释代码,真是有点让人瞎眼的感觉 去这个网站 https://github.com/mig/gedit-themes/tree/master 下载所有后解压到/usr/share/gtk ...
- Ubuntu 使用unzip解压乱码的问题
由于win使用的是GBK编码,在win下打包zip的压缩文件在ubuntu下使用unzip解压会出现乱码的问题. 解决方案: 换软件,不用unzip,使用unar 18.04是默认安装的,如果没有默认 ...
- Images之Dockerfile中的命令2
COPY COPY has two forms: COPY [--chown=<user>:<group>] <src>... <dest> COPY ...
- Python多线程爬虫
前言 用上多线程,感觉爬虫跑起来带着风 运行情况 爬取了9万多条文本记录,耗时比较短,一会儿就是几千条 关键点 多个线程对同一全局变量进行修改要加锁 # 获取锁,用于线程同步 threadLock.a ...
- 【译】第21节---Fluent API
原文:http://www.entityframeworktutorial.net/code-first/fluent-api-in-code-first.aspx 在前面的学习中.我们已经看到不同的 ...
- [UVA-11039]Children's Game
解析 微扰法贪心经典题 代码 #include <bits/stdc++.h> using namespace std; bool cmp(const string &x, con ...
- BZOJ 1055: [HAOI2008]玩具取名(记忆化搜索)
http://www.lydsy.com/JudgeOnline/problem.php?id=1055 题意: 思路:记忆化搜索. #include<iostream> #include ...
- WinForm 拖动、移动窗体
private const int WM_NCLBUTTONDOWN = 0XA1; private const int HTCAPTION = 2; [System.Runtime.InteropS ...
- R语言可视化学习笔记之ggpubr包—SCI文章图
转载:https://www.jianshu.com/p/678213d605a5?from=jiantop.com Hadley Wickham创建的可视化包ggplot2可以流畅地进行优美的可视化 ...
- 【Web Service】
Restful: (Representational State Transfer 表现层[指客户端]状态[指服务器端]转化) RPC: RPC 风格的开发关注于服务器/客户端之间的方法调用, 而并 ...