CodeForces 493D Vasya and Chess 简单博弈

Vasya and Chess

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

CodeForces 493D

Description

Vasya decided to learn to play chess. Classic chess doesn‘t seem interesting to him, so he plays his own sort of chess.

The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy‘s piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.

There is an n × n chessboard. We‘ll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1)contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don‘t belong to anyone.

The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.

On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.

Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.

Input

The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.

Output

On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.

If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.

Sample Input

Input

2

Output

white1 2

Input

3

Output

black

Hint

In the first sample test the white queen can capture the black queen at the first move, so the white player wins.

In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).

Similarly, the black queen doesn‘t have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.

During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).

In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins.

题意:黑白皇后在棋盘上可以横着走竖着都对角线走 前提是走到的地方要有一个棋子给你吃  不能跨过一个棋子去吃另外一个棋子

棋盘上除了黑白皇后其他地方都铺满了中立单位 随便吃  白的先走 问谁会赢 白赢的话给出第一步怎么走

第一次做博弈  因为是对称的所以很水  草稿上把n试到4的时候结论就差不多出来了

我的理解是white和black第一步都要往中间靠 然后谁先迫不得已往下走谁就输了

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;

int main()
{
    int n;
    cin>>n;
    if(n%2!=0)  printf("black\n");
    else  printf("white\n1 2\n");
    return 0;
}

  

时间: 2024-10-12 15:51:23

CodeForces 493D Vasya and Chess 简单博弈的相关文章

codeforces 493D Vasya and Chess(博弈?)

传送门:点击打开链接 题目大意: 给一个N*N的棋盘.然后一开始 白队的Queen在(1,1),黑队的Queen在(1,n). 其余的点都是绿棋子. Queen可以走横竖和斜线.(就是国际象棋里面Queen的走法,但是必须要吃子). 问白方先走.谁能嬴(没得走或者被吃了就死了) 解题思路: 博弈题..习惯性乱猜 就过了.写的比A还快. 猜法如下:每个人各走一步,可以使得总奇偶性不变.然后只要知道一开始的距离的奇偶性.就知道谁先死了.(勿喷) #include <cstdio> #include

codeforces 493 D Vasya and Chess【 博弈 】

题意:给出n*n的棋盘,白方在(1,1),黑方在(1,n)处,每一步可以上下左右对角线走,哪个先抓到另一个,则它获胜 可以画一下,发现n是奇数的时候,白方先走,无论它怎么走,黑方和它走对称的,黑方都一定能赢 n是偶数的时候,将白方走到(1,2)就变成奇数的情况,白方必胜 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<st

Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈

D. Vasya and Chess Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is

Codeforces 15C Industrial Nim 简单博弈

题目链接:点击打开链接 题意: 给定n 下面n行,每行2个数u v 表示有v堆石子:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先根据Nim的博弈结论 把所有数都异或一下,看结果是0还是非0 而这里因为数字太多所以想优化 那么其实对于一个序列 u, u+1, u+2 ···· 显然 {4,5} {,6,7}, {8,9} 这样2个一组的异或结果就是1 那么只需要把序列分组,分成{偶数,奇数} 然后Y一下.. #include<stdio.h> #include<

ACM: NBUT 1107 盒子游戏 - 简单博弈

NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format: Practice Appoint description:  System Crawler  (Aug 13, 2016 10:35:29 PM) Description 有两个相同的盒子,其中一个装了n个球,另一个装了一个球.Alice和Bob发明了一个游戏,规则如下:Alice和Bob轮流操作,Alice先操作每次操作时,游戏者先看看

HDU 1846 Brave Game (简单博弈)

HDU 1846 Brave Game (简单博弈) ACM 题目地址: HDU 1846 Brave Game 题意: 中文. 分析: 博弈入门. 如果n=m+1,因为最多取m个,所以先拿的人拿多少个,后拿的人能全拿走. 所以判断n%(m+1)即可. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1846.cpp * Create Date: 2014-09-20 10:05:26 * Descripton: game */ #

CodeForces 577C Vasya and Petya&#39;s Game 数学

题意就是给你一个1到n的范围 你每次可以问这个数是否可以被某一个数整除 问你要猜多少数才能确定这个数…… 一开始一点思路也没有 后来查了一下才知道 每个数都可以分为几个质数的整数次幂相乘得到…… 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string>

[简单博弈] hdu 1525 Euclid&#39;s Game

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1525 Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1832    Accepted Submission(s): 808 Problem Description Two players, Stan and

CodeForces - 837E - Vasya&#39;s Function | Educational Codeforces Round 26

/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b-gcd(a, b)); 求 f(a, b) , a,b <= 1e12 分析: b 每次减 gcd(a, b) 等价于 b/gcd(a,b) 每次减 1 减到什么时候呢,就是 b/gcd(a,b)-k 后 不与 a 互质 可先将 a 质因数分解,b能除就除,不能