您的位置:首页 > 其它

Codeforces - 493D. Vasya and Chess - 博弈

2017-07-05 17:08 246 查看

Vasya and Chess

题目链接

分类:博弈、思维

1.题意概述

一个n×n的棋盘,白皇后在(1,1)处,黑皇后在(1,n)处,其余坐标为绿色棋子。皇后每次可以走行、列、对角线,但是要求每一步必须吃掉棋子或者对方皇后。问你这种策略下哪一方最终能够获胜?

2.解题思路

我们先观察一下规律:

当n为2时候,先手(白)必胜

当n为3时候,后手(黑)必胜

当n为4时候,先手(白)可以往右侧行一格,那么情况就转变成了n为3时候黑白互换先后手

然后归纳出一般情况:n为奇数,黑必胜;n为偶数,白必胜!

我们还可以这样考虑,以对称轴为中心,白如何走,黑就跟着走,最后状态一定是在对称轴结束,当n为偶数,一定是黑先过对称轴,而当n为奇数一定是白先到对称轴,后者赢。

3.AC代码

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100010
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
int n;
scanf("%d", &n);
printf(n & 1 ? "black\n" : "white\n1 2\n");
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces