CUC-SUMMER-6-D

D - Vasya and Chess
CodeForces - 493D

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.

Example
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.


題意:白皇后在(1,1)處摸吠,黑皇后在(1,n)處滤否,棋盤其余處為其他棋子废累,皇后可以水平、垂直或斜向吃子酱讶,但不能隔著棋子吃子,一個皇后吃掉另一個皇后就贏了。白皇后先走刁笙,問黑白那個贏,如果白皇后贏那么第一步怎么走拉一。

解法:在3x3棋盤采盒,黑贏,在4x4的棋盤白先右移1則情況等同于3x3棋盤黑先走蔚润,所以白贏磅氨,依次類推。所有奇數(shù)棋盤黑贏嫡纠,偶數(shù)白贏烦租。

代碼:

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%2==1)
        cout<<"black"<<endl;
    else
        cout<<"white"<<endl<<"1 2"<<endl;
}
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末延赌,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子叉橱,更是在濱河造成了極大的恐慌挫以,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,188評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件窃祝,死亡現(xiàn)場離奇詭異掐松,居然都是意外死亡,警方通過查閱死者的電腦和手機粪小,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,464評論 3 395
  • 文/潘曉璐 我一進店門大磺,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人探膊,你說我怎么就攤上這事杠愧。” “怎么了逞壁?”我有些...
    開封第一講書人閱讀 165,562評論 0 356
  • 文/不壞的土叔 我叫張陵流济,是天一觀的道長。 經(jīng)常有香客問我腌闯,道長绳瘟,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,893評論 1 295
  • 正文 為了忘掉前任绑嘹,我火速辦了婚禮稽荧,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘工腋。我一直安慰自己姨丈,他們只是感情好,可當我...
    茶點故事閱讀 67,917評論 6 392
  • 文/花漫 我一把揭開白布擅腰。 她就那樣靜靜地躺著蟋恬,像睡著了一般。 火紅的嫁衣襯著肌膚如雪趁冈。 梳的紋絲不亂的頭發(fā)上歼争,一...
    開封第一講書人閱讀 51,708評論 1 305
  • 那天,我揣著相機與錄音渗勘,去河邊找鬼沐绒。 笑死,一個胖子當著我的面吹牛旺坠,可吹牛的內(nèi)容都是我干的乔遮。 我是一名探鬼主播,決...
    沈念sama閱讀 40,430評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼取刃,長吁一口氣:“原來是場噩夢啊……” “哼蹋肮!你這毒婦竟也來了出刷?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,342評論 0 276
  • 序言:老撾萬榮一對情侶失蹤坯辩,失蹤者是張志新(化名)和其女友劉穎馁龟,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體漆魔,經(jīng)...
    沈念sama閱讀 45,801評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡坷檩,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,976評論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了有送。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片淌喻。...
    茶點故事閱讀 40,115評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖雀摘,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情八拱,我是刑警寧澤阵赠,帶...
    沈念sama閱讀 35,804評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站肌稻,受9級特大地震影響清蚀,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜爹谭,卻給世界環(huán)境...
    茶點故事閱讀 41,458評論 3 331
  • 文/蒙蒙 一枷邪、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧诺凡,春花似錦东揣、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,008評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至凉袱,卻和暖如春芥吟,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背专甩。 一陣腳步聲響...
    開封第一講書人閱讀 33,135評論 1 272
  • 我被黑心中介騙來泰國打工钟鸵, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人涤躲。 一個月前我還...
    沈念sama閱讀 48,365評論 3 373
  • 正文 我出身青樓棺耍,卻偏偏與公主長得像,于是被迫代替她去往敵國和親篓叶。 傳聞我的和親對象是個殘疾皇子烈掠,可洞房花燭夜當晚...
    茶點故事閱讀 45,055評論 2 355

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,511評論 0 23
  • 出了兩本Spark的圖書 《Spark大數(shù)據(jù)分析實戰(zhàn)》 《Spark大數(shù)據(jù)處理:技術羞秤、應用與性能優(yōu)》 微信讀書都有...
    Albert陳凱閱讀 522評論 0 0
  • 1、歌訣法記憶《觀滄鹤蟮校》 東臨碣石瘾蛋,以觀滄海。水何澹澹矫限,山島竦峙哺哼。樹木叢生,百草豐茂叼风。秋風蕭瑟取董,洪波涌起。日月之行...
    文魁大腦蕭進才閱讀 324評論 2 0
  • 現(xiàn)代社會競爭蕪雜无宿,人才濟濟茵汰,要想立于不敗之地届巩,有一身過硬的本領是必須的型凳,站立的平臺也很重要哦葫督。就像看大型演...
    茜茜_1314_smile閱讀 132評論 0 0
  • 有一天琅拌,殘風過境但惶,蕭瑟落黃 我慢慢地清掃一片片的孤獨 就像盡數(shù)一天天生年,周一到周日 形單影只常柄,獨自一人 碼成堆赤套,在棕...
    咿_03da閱讀 423評論 0 3