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态(必胜态),那么和上边的分析一样了,因此先手必败。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
/* *********************************************** Author :111qqz Created Time :2016年11月18日 星期五 21时28分43秒 File Name :code/bzoj/2463.cpp ************************************************ */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <cmath> #include <cstdlib> #include <ctime> #define fst first #define sec second #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define ms(a,x) memset(a,x,sizeof(a)) typedef long long LL; #define pi pair < int ,int > #define MP make_pair using namespace std; const double eps = 1E-8; const int dx4[4]={1,0,0,-1}; const int dy4[4]={0,-1,1,0}; const int inf = 0x3f3f3f3f; int main() { #ifndef ONLINE_JUDGE freopen("code/in.txt","r",stdin); #endif int n; while (~scanf("%d",&n)&&n) { if (n%2==1) puts("Bob"); else puts("Alice"); } #ifndef ONLINE_JUDGE fclose(stdin); #endif return 0; } |
.
说点什么
您将是第一位评论人!