首页 > 代码库 > 【bzoj2463】 谁能赢呢?
【bzoj2463】 谁能赢呢?
www.lydsy.com/JudgeOnline/problem.php?id=2463 (题目链接)
题意:一个n*n的棋盘,开始时左上角有一个棋子,每次可以把棋子向4个方向移动,但不能移动到曾经走过的格子上,无法移动者输,问是否存在先手必胜策略。
Solution
手玩了一下n<=4的情况,发现当n是偶数时就有必胜策略,交上去果然AC。。然而不会证明,于是翻了下别人的题解。
当n为偶数时,可以被2*1的骨牌完全覆盖,所以每次都走骨牌的另一端,而另一个
人只能走新的骨牌,直到没有为止
当n为奇数时,去掉第一个格子后可以被2*1的骨牌完全覆盖,所以胜负反过来了
很有道理阿有木有。
代码:
// bzoj2463#include<algorithm>#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>#define LL long long#define inf 2147483640#define Pi acos(-1.0)#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);using namespace std;int main() { int n; while (scanf("%d",&n)!=EOF && n) { if (n&1) printf("Bob\n"); else printf("Alice\n"); } return 0;}
【bzoj2463】 谁能赢呢?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。