POJ 2425 A Chess Game#树形SG
http://poj.org/problem?id=2425
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; struct node
{
int to,next;
}e[10000010];
int head[1010],Ecou;
int sg[1010]; void add_edge(int u,int v)
{
e[Ecou].to=v;
e[Ecou].next=head[u];
head[u]=Ecou++;
} int getsg(int n)
{
if(sg[n]!=-1)
return sg[n]; bool vis[1010];
memset(vis,0,sizeof(vis));
for(int i=head[n];i>=0;i=e[i].next)
{
sg[e[i].to]=getsg(e[i].to);
vis[sg[e[i].to]]=1;
}
for(int i=0;;i++)
if(!vis[i])
return sg[n]=i;
} int main()
{
int n;
while(~scanf("%d",&n))
{
memset(head,-1,sizeof(head));
Ecou=0;
int num,a;
for(int i=0;i<n;i++)
{
scanf("%d",&num);
while(num--)
{
scanf("%d",&a);
add_edge(i,a);
}
}
memset(sg,-1,sizeof(sg));
while(1)
{
int m,x,ans=0;
scanf("%d",&m);
if(!m) break; while(m--)
{
scanf("%d",&x);
ans^=getsg(x);
}
if(ans) printf("WIN\n");
else printf("LOSE\n");
}
}
return 0;
}
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函数)题解
题意:给一个有向图,然后个m颗石头放在图上的几个点上,每次只能移动一步,如果不能移动者败 思路:dfs打表sg函数,然后求异或和 代码: #include<queue> #include& ...
- 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 2599 A funny game#树形SG(DFS实现)
http://poj.org/problem?id=2599 #include<iostream> #include<cstdio> #include<cstring&g ...
- pku 2425 A Chess Game (SG)
题意: 给一个由N个点组成的一张有向图,不存在环.点的编号是0~N-1. 然后给出M个棋子所在的位置(点的编号)[一个点上可同时有多个棋子]. 每人每次可移动M个棋子中的一个棋子一步,移动方向是有向边 ...
- poj 2425 AChessGame(博弈)
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3791 Accepted: 1549 Desc ...
随机推荐
- 动态网站加速,cdn义不容辞
"双十一"大战已经落下帷幕,各大电商纷纷拿出了亮眼的成绩单,但在这些成绩单的背后,CDN加速技术是功不可没的.随着互联网的发展,电商.视频直播等网站的火热,以及各个云加速平台的流行 ...
- 解决 maven项目问题 An error occurred while filtering resources
解决方法: Maven -> Update Project.
- CreateMutex()参数报错问题
举例: hMutex = CreateMutex(NULL, FALSE,"screen"); 报错 error C2664:"CreateMutexW": 不 ...
- hdu2159二维费用背包
题目连接 背包九讲----二维费用背包 问题 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有一个可付出的最大值(背包容量).问怎样选择物 ...
- WindowsServer2012 R2 64位中文标准版(IIS8.5)下手动搭建PHP环境详细图文教程(二)安装IIS8.5
//来源:http://www.imaoye.com/Technology/WindowsServer2012R264IIS85.html 阿里云服务器ECS Windows Server 2012 ...
- form -转载于blfshiye
Form API 表单API 文件夹 1.概述 2.亮点 3.使用方法 4.表单元素 4.1 基本表单元素 4.2 定制表单元素 5.经常使用函数 5.1 add_action_buttons($c ...
- URLEncode编码和URLDecode解码
String text1 = java.net.URLEncoder.encode("中国" ,"utf-8" ); String text2 = java.n ...
- ora2pg数据迁移
1.安装strawberry-perl-5.242.安装ora2pg-17.4 #perl Makefile.PL #dmake && dmake install3.安装ora2pg相 ...
- Elasticsearch相关配置(二)
一.关于elasticsearch的基本概念 term 索引词,在elasticsearch中索引词(term)是一个能够被索引的精确值.foo,Foo Foo几个单词是不相同的索引词.索引词(ter ...
- 特性(Attributes)
用以将元数据或声明信息与代码(程序集.类型.方法.属性等)相关联.特性与程序实体相关联后,即可在运行时用反射技术查询特性. 例如,在一个方法前标注[Obsolete]特性,则调用该方法时VS则会提示该 ...