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[]; ],Ecou; ]; void add_edge(int u,int v) { e[Ecou].to=v; e[Ecou].next=head[…
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vis数组应该在函数内声明(似乎这是我经常在搜索里犯的错误,为了省一点空间整道题都写错了): 2.是n个点的有向无环图边数上限是n^2(re了好久QAQ). 在漫长的查资料过程之后终于大概搞懂了sg函数的原理,愉快.下一篇大概会写一个小结. 代码 #include<cstdio> #include&l…
A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3551   Accepted: 1440 Description Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesses can be located in the same position. The…
题意:给一个有向图,然后个m颗石头放在图上的几个点上,每次只能移动一步,如果不能移动者败 思路:dfs打表sg函数,然后求异或和 代码: #include<queue> #include<cstring> #include<set> #include<map> #include<stack> #include<cmath> #include<vector> #include<cstdio> #include&l…
思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<vector> #include<cstring> using namespace std; ],n; vector<]; int dfs(int now) { ) return sg[now]; ]={}; ;i<p[now].size();i++) vis[dfs(p[now…
题目链接题意:给定一个有向无环图(DAG),上面放有一些旗子,旗子可以重合,两个人轮流操作,每次可以把一个旗子从一个位置移动到相邻的位置,无法移动时输,询问先手是否必胜. 这道题可以把每个旗子看作单独的一个游戏,那么所有这些旗子的状态SG值,就是这些旗子各自SG值的Xor和,可以记忆化搜索dfs,暴力算SG值判断即可. #include<iostream> #include<cstdio> #include<algorithm> #include<cstring&…
题意:给你一个有向无环图,再给你图上的棋子,每人每次只能移动一个棋子,当轮到你不能移动棋子是就输了,棋子可以同时在一个点 比赛时就差这题没ak,做了几天博弈终于搞懂了. #include <iostream> #include <cstdio> #include<vector> #include<cstring> using namespace std; #define N 1010 vector<int> adj[N]; int sg[N],n…
http://poj.org/problem?id=2599 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; int n,k,pos; vector<]; ]; int dfs(int k) { ;i<g[k].size();i++) { int t=g[k][…
题意: 给一个由N个点组成的一张有向图,不存在环.点的编号是0~N-1. 然后给出M个棋子所在的位置(点的编号)[一个点上可同时有多个棋子]. 每人每次可移动M个棋子中的一个棋子一步,移动方向是有向边指向的方向.最后无法移动棋子的人输. 思路: 一眼就可看出的裸的SG,直接看代码吧. 代码: int sg[1005]; vector<int> graph[1005]; int dfs(int x){ // position x if(sg[x]!=-1) return sg[x]; int L…
A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3791   Accepted: 1549 Description Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesses can be located in the same position. The…