[poj2425]A Chess Game_博弈论
A Chess Game poj-2425
题目大意:题目链接
注释:略。
想法:这个题就是为什么必须要用记忆化搜索。因为压根就不知道后继是谁。
我们通过SG定理可知:当前游戏的SG值等于所有子游戏的SG的异或和。
我们就可以dp了。
最后,附上丑陋的代码... ...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1010
int sg[N],n,x,ans,m;
int SS[N];
int tot,to[N*N<<1],head[N],nxt[N*N<<1],cnt[N],num;
inline void add(int x,int y) {to[++tot]=y; nxt[tot]=head[x]; head[x]=tot;}
int dfs(int pos)
{
if(sg[pos]!=-1) return sg[pos];
bool vis[N];
for(int i=0;i<n;i++) vis[i]=false;
for(int i=head[pos];i;i=nxt[i]) vis[dfs(to[i])]=true;
for(int i=0;;i++) if(!vis[i]) return sg[pos]=i;
}
int main()
{
while(~scanf("%d",&n))
{
memset(sg,-1,sizeof sg);
memset(head,0,sizeof head);
memset(cnt,0,sizeof cnt);
tot=0;
for(int i=0;i<n;i++)
{
scanf("%d",&num);
for(int j=1;j<=num;j++)
{
scanf("%d",&x);
add(i,x);
cnt[x]++;
}
}
for(int i=0;i<n;i++) if(!cnt[i]) sg[i]=dfs(i);
while(scanf("%d",&m)&&m)
{
ans=0;
for(int i=1;i<=m;i++)
{
scanf("%d",&x);
ans^=sg[x];
}
if(ans) printf("WIN\n");
else printf("LOSE\n");
}
}
}
小结:血泪教训:dfs那个vis必须开局部!!不然搜的时候memset全炸了... ...
[poj2425]A Chess Game_博弈论的更多相关文章
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 镜面对称 博弈论
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- poj 2425 A Chess Game 博弈论
思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include< ...
- hdu 1524 A Chess Game 博弈论
SG函数!! 代码如下: #include<stdio.h> #include<cstring> #define I(x) scanf("%d",& ...
- HDU 5724 Chess(博弈论)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5724 [题目大意] 给出一个n行,每行有20格的棋盘,棋盘上有一些棋子,每次操作可以选择其中一个棋 ...
- POJ2425 A Chess Game(SG函数+记忆化深搜)
题目链接:传送门 题目大意: 在一个有N个点的拓扑图上(拓扑图以邻接表的形式输入),放M个棋子(棋子与棋子之间无关,可以重合). 两人轮流移动棋子,每次只能移动一个棋子经过一条边. 问先手是否必胜. ...
- POJ 2425 A Chess Game 博弈论 sg函数
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...
- [poj2505]A multiplication game_博弈论
A mutiplication game poj-2505 题目大意:给定一个数n和p,两个选手每次可以将p乘上[2,9].最先使得p大于n的选手胜利. 注释:$1\le n\le 429496729 ...
- [poj2234]Matces Game_博弈论
Matches Game poj-2234 题目大意:n堆石子的Nim游戏,anti-SG. 注释:$1\le n\le 20$. 想法:用Colon定理即可.具体见:小约翰的游戏 最后,附上丑陋的代 ...
随机推荐
- 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先
给定一棵二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-s ...
- 图标文件ico制作以及使用说明
今天说一个图标文件——ico.我们在pc端浏览网页的时候网页栏那块都会显示一个本网站特有的图片,就是我们说的ico了.示例:<link href="image/favicon.ico& ...
- Redux 中的CombineReducer的函数详解
combineReducers(reducers) 随着应用变得复杂,需要对 reducer 函数 进行拆分,拆分后的每一块独立负责管理 state 的一部分. combineReducers 辅助函 ...
- Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框
Activity: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...
- 分布式缓存系统Memcached[分享]
个人网站:http://www.51pansou.com memcached视频下载:memcached视频教程 memcached源码下载:memcached源码 Memcached是什么? Mem ...
- Codeforces_768_B_(二分)
B. Code For 1 time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- HDU_1203_01背包
I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- OpenGL坐标系之间的转换 http://blog.csdn.net/sac761/article/details/52179585
1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观测变换(ModelView Transformation)和投影变换(Projection Transformation).做个比 ...
- nginx做反向代理配置文件的例子
worker_processes ; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error ...
- 关于iframe与$.load()哪个更好
iframe与$.load()哪个更好 iframe可以直接加载页面,但是要付出降低搜索引擎搜索效率的代价,它引入静态文件的方式是完全独立的,简单意思就是,在页面一(父级页面)用ifram ...