bzoj 2463: [中山市选2009]谁能赢呢? (博弈论)
2463: [中山市选2009]谁能赢呢?
Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1826 Solved: 1347 [Submit][Status][Discuss]
Description
小明和小红经常玩一个博弈游戏。给定一个n×n的棋盘,一个石头被放在棋盘的左上角。他们轮流移动石头。每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的格子之前不能被访问过。谁不能移动石头了就算输。假如小明先移动石头,而且两个选手都以最优策略走步,问最后谁能赢?
Input
输入文件有多组数据。
输入第一行包含一个整数n,表示棋盘的规模。
当输入n为0时,表示输入结束。
Output
对于每组数据,如果小明最后能赢,则输出”Alice”, 否则输出”Bob”, 每一组答案独占一行。
Sample Input
2 0
Sample Output
Alice
HINT
对于所有的数据,保证1<=n<=10000。
思路:手写了下几组猜是奇偶性..写了下就过了。
证明:
**首先对于n是偶数,一定能被1*2的骨牌覆盖!所以从起点开始,先手一定走的是骨牌的另一端,后手一定走的是骨牌的前一端,因此无论何时,先手总是可以走。因此先手必胜。**如果n是奇数,那么去掉一格后一定能被1*2的骨牌覆盖,但是先手从左上角走,就进入了这个S态(必胜态),那么和上边的分析一样了,因此先手必败。
/* ***********************************************
Author :111qqz
Created Time :2016年11月18日 星期五 21时28分43秒
File Name :code/bzoj/2463.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6int main()
7{
8 #ifndef ONLINE_JUDGE
9 freopen("code/in.txt","r",stdin);
10 #endif
11 int n;
12 while (~scanf("%d",&n)&&n)
13 {
14 if (n%2==1) puts("Bob");
15 else puts("Alice");
16 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}
**.**