POJ 3537 Crosses and Crosses
2017-02-25 11:07
387 查看
Crosses and Crosses
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 3514 | Accepted: 1372 | |
Case Time Limit: 2000MS |
Description
The game of Crosses and Crosses is played on the field of 1 × n cells. Two players make moves in turn. Each move the player selects any free cell on the field and puts a cross ‘×’ to it. If after the player’s move there are three crosses in a row, he wins.You are given n. Find out who wins if both players play optimally.
Input
Input file contains one integer number n (3 ≤ n ≤ 2000).Output
Output ‘1’ if the first player wins, or ‘2’ if the second player does.Sample Input
#1 | 3 |
---|---|
#2 | 6 |
Sample Output
#1 | 1 |
---|---|
#2 | 2 |
Source
Northeastern Europe 2007, Northern Subregion分析:
显然,如果一个棋子放在了棋盘上,那么这个棋子的左边两个位置和右边两个位置都不能再放棋子,问题就转化为了一个棋子的左右两边的四个位置不能放,谁不能放谁输...对于一个$1*n$的棋盘我们把其看成一个规模为$n$的游戏,这个游戏的后继状态我们可以$O(N)$的枚举计算,所以我们可以算出所有游戏的$SG$函数...
代码:
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> //by NeighThorn using namespace std; const int maxn=2000+5; int n,f[maxn]; inline int sg(int x){ if(f[x]!=-1) return f[x]; bool vis[maxn]; memset(vis,0,sizeof(vis)); for(int i=1;i<=x;i++) vis[sg(max(0,i-3))^sg(max(x-i-2,0))]=1; for(int i=0;;i++) if(!vis[i]) return f[x]=i; } signed main(void){ scanf("%d",&n); memset(f,-1,sizeof(f));f[0]=0; puts(sg(n)?"1":"2"); return 0; }
By NeighThorn
相关文章推荐
- POJ 3537 Crosses and Crosses
- POJ 3537 Crosses and Crosses
- POJ 3537 Crosses and Crosses 已翻译
- poj 3537 Crosses and Crosses 博弈论之grundy值
- poj 3537 Crosses and Crosses(NIM变形)@
- POJ 3537 Crosses and Crosses
- POJ 3537 Crosses and Crosses(SG/还未想完全通的一道SG)
- POJ-3537 Crosses and Crosses (博弈, SG函数)
- poj 3537 Crosses and Crosses (SG)
- POJ 3537 Crosses and Crosses
- poj 3537 Crosses and Crosses (Multi-SG游戏)
- POJ-3537-Crosses and Crosses
- poj 3537 Crosses and Crosses 博弈论
- POJ 3537 Crosses and Crosses
- POJ 3537 Crosses and Crosses [Multi-SG]
- POJ 3537:Crosses and Crosses(Multi-Nim)
- POJ-3537(Crosses and Crosses)——博弈论,SG函数
- 【POJ】【3537】Crosses and Crosses
- POJ-3537-Crosses and Crosses
- poj_Crosses and Crosses_3537