您的位置:首页 > 其它

Codeforces Round #281 (Div. 2)D. Vasya and Chess(博弈,想法题)

2016-11-25 22:52 381 查看
D. Vasya and Chess

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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.

Examples

input
2


output
white
1 2


input
3


output
black


Note

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*N的棋盘。然后一开始 白队的Queen在(1,1),黑队的Queen在(1,n)。

其余的点都是绿棋子。

Queen可以走横竖和斜线。(就是国际象棋里面Queen的走法,但是必须要吃子)。

绿子被吃了就不能走那一个格子了。

问白方先走。谁能嬴(没得走或者被吃了就死了)

题解:
当n为奇数时先手必败,只要后手和先手对称走就行了。

当n为偶数时,先手可以机智的向右走一个,后面再也不向左边走,然后就黑皇后处在先手必败的状态了。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
int main()
{
int n;
cin >> n;
if(n&1)
puts("black");
else
printf("white\n1 2");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: