[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定理即可.具体见:小约翰的游戏 最后,附上丑陋的代 ...
随机推荐
- 解决:阿里云ECS上启动tomcat后,第一次访问时间特别长
Re在ECS上启动tomcat后,第一次访问时间特别长 2017-04-25 10:16:04 INFO com.world.socket.ServerSocketListener 25- ...
- Snipaste强大离线/在线截屏软件的下载、安装和使用
步骤一: https://zh.snipaste.com/ ,去此官网下载. 步骤二:由于此是个绿色软件,直接解压即可. 步骤三:使用,见官网.ttps://zh.snipaste.com 按F1 ...
- C#基础 集合
//数组定义的时候 //需要定义数据类型 //需要定义初始长度 //int [] array = new int[5]; //int a = array.Length; //集合 //ArrayLis ...
- myBatis逆向生成及使用
引入数据库驱动 <!-- mybatis逆向生成包 --><dependency> <groupId>org.mybatis.generator</group ...
- C:\Windows\System32\drivers\etc\hosts文件显示
attrib -s -h C:\Windows\System32\drivers\etc\hosts
- V形
<!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...
- axios方法get及post代码示例
show: function(){ //get方式 //赋值给变量self var self = this; var url = "hotcity.json"; axios.get ...
- ThinkPHP---layer插件
[概论] (1)layer是基于jquery开发的一款美化弹框的插件,主要用于弹框效果的交互.但其他功能和组件也日益完善 官网:http://layer.layui.com 在线手册:http://w ...
- Python自学-1-基本概念问题
C语言适合开发那些追求运行速度.充分发挥硬件性能的程序. Python是用来编写应用程序的高级编程语言. Python提供了 第三方库 & 基础代码库(覆盖了网络.文件.GUI.数据库.文本等 ...
- scala学习(3)-----wordcount【sparksession】
参考: spark中文官方网址:http://spark.apachecn.org/#/ https://www.iteblog.com/archives/1674.html 一.知识点: 1.Dat ...