POJ 2425 A Chess Game(有向图SG函数)题解
题意:给一个有向图,然后个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函数)题解的更多相关文章
- 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
http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring&g ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
- poj 2425 A Chess Game 博弈论
思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include< ...
- poj 3575 Crosses and Crosses(SG函数)
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3063 Accepted: 11 ...
- poj 2425 A Chess Game_sg函数
题意:给你一个有向无环图,再给你图上的棋子,每人每次只能移动一个棋子,当轮到你不能移动棋子是就输了,棋子可以同时在一个点 比赛时就差这题没ak,做了几天博弈终于搞懂了. #include <io ...
- pku 2425 A Chess Game (SG)
题意: 给一个由N个点组成的一张有向图,不存在环.点的编号是0~N-1. 然后给出M个棋子所在的位置(点的编号)[一个点上可同时有多个棋子]. 每人每次可移动M个棋子中的一个棋子一步,移动方向是有向边 ...
- HDU 1524 A Chess Game【SG函数】
题意:一个N个点的拓扑图,有M个棋子,两个人轮流操作,每次操作可以把一个点的棋子移动到它的一个后继点上(每个点可以放多个棋子),直到不能操作,问先手是否赢. 思路:DFS求每个点的SG值,没有后继的点 ...
随机推荐
- TortoiseGit的使用
TortoiseGit只是一个外壳而已,它调用的是msysgit,相当于msysgit的windows gui而已,如果喜欢用git命令行,那就不需要安装它. 所以要先安装msysgit(window ...
- 15款Django开发常用软件包(转)
原文:http://www.iteye.com/news/28697 Django是一款高级的Python Web框架,可以帮助开发者快速创建web应用.我们这里整理了15款Django开发中常用的软 ...
- ViewPager的OnPageChangeListener三个回调解析
一个native crash最后是重写ViewPager解决的,过程中发现这三个回调还有点绕,于是理了一下 ViewPager有两个操作,一个是用手指滑动翻页,一个是直接setCurrentItem( ...
- 在linux下使用sqlcmd
1.curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.re ...
- visio 的使用方法
1:往visio中添加商务图形和形状的方法.例如饼状图. 文件>形状>商务>图表和图形>绘制图表形状 2:visio 画半弧形,用铅笔 3: visio 画的图形,如果想要和v ...
- Oracle数据库返回字符类型-1~1的结果处理
如果实体类中定义的字段是String类型,Oracle数据库中返回的是数字类型,那么Oracle返回0.xxx的时候会丢失前面的0. 要想不丢失0,那么数据库返回的就要是字符串类型的,所以要将返回值转 ...
- CloudFlare防护下的破绽:寻找真实IP的几条途径
本文仅代表作者独立观点,本文提及的技术仅供安全研究和渗透测试用途 看Twitter发现CloudFlare总裁什么的最近很高调,北京.香港的跑着参加会议.发表演说什么的,CloudFlare似乎也没那 ...
- Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
转自http://www.anylogic.com/anylogic/help/index.jsp?topic=/com.xj.anylogic.help/html/code/Arrays_Colle ...
- Summary: Difference between null and empty String
String s1 = ""; means that the empty String is assigned to s1. In this case, s1.length() i ...
- PKU2503_map应用
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...