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; }
相关文章推荐
- Vasya and Chess - CodeForces 493 D 博弈
- codeforces 493 D Vasya and Chess【 博弈 】
- Vasya and Chess - CodeForces 493 D 博弈
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈
- Codeforces Round #281 (Div. 2)D. Vasya and Chess(博弈,想法题)
- 【29.89%】【codeforces 734D】Anton and Chess
- codeforces 560 E. Gerald and Giant Chess (dp+lucas定理,求大组合数 mod p,p为质数)
- codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)
- (尺取法)Codeforces 676C - Vasya and String
- codeforces 559C Gerald and Giant Chess (dp+乘法逆元)
- Gerald and Giant Chess (CodeForces - 560E)(组合数)
- Codeforces 355C Vasya and Robot【贪心+前缀和】
- 【Codeforces Round #313 (Div. 1) C】 CodeForces 559C Gerald and Giant Chess
- Codeforces 560E Gerald and Giant Chess 组合数学+DP
- Codeforces 559C Gerald and Giant Chess(组合数学+DP)
- Codeforces 584 C. Marina and Vasya (Codeforces Round #324 (Div. 2))
- [CodeForces] Round #313 Div 2 E / Div 1 C Gerald and Giant Chess 不用容斥的递推组合数学
- Codeforces 560 E. Gerald and Giant Chess (dp,组合数学)
- Codeforces 355C Vasya and Robot 暴力枚举
- CodeForces 354A - Vasya and Robot 简单思维..赋初值一定不能随便了T_T