BZOJ - 2463 谁能赢呢? (简单博弈)

题意: 给你一个n*n的棋盘,一个石头被放在棋盘的左上角。他们轮流移动石头。每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的格子之前不能被访问过。谁不能移动石头了就算输。假如小明先移动石头,而且两个选手都以最优策略走步,问最后谁能赢?

思路: 每次只能移动一格,且走过的路不能走,那就看最多能走几步被,看看最多的步数是奇数还是偶数,奇数后手赢,偶数先手赢就ok了

上代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		if(n == 0)break;
		
		if((n*n)&1)
		{
			puts("Bob");
		}
		else puts("Alice");
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/wjmwsgj/article/details/80195572