码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1924 Four Imps (博弈论 + 规律)

时间:2015-03-06 19:09:08      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

1924. Four Imps

Time limit: 1.0 second
Memory limit: 64 MB
The world is in danger. One famous swindler passed away recently (by the way, nobody knows his real name, so let‘s call him Ostap). Having got to the hell he decided to make a deal with the Devil. More precisely, it was, actually, not a deal but a stake in a totalizator. The rules of the game are quite simple. Several imps divide into two teams — “black” and “grimy”. Then they go to the game field. Numbers from 1 to n are written on the field, and the teams do their turns one after another by putting down with black ink signs of + and ? between the numbers. When there is no two adjacent numbers without sign between them left, players calculate the result of obtained expression on the field. The goal of the “black” team is to make this result even, the goal of the “grimy” team is to make it odd. All four imps are experts in this game, therefore they always do optimal turns. “Black” team plays first.
The totalizator rules are the following: if Ostap guesses which team wins, he will get his life back. Otherwise, the Devil will get the power over the whole world. The stakes are high, so you have to help Ostap with determining the winner.

Input

The input is a single integer n (1 ≤ n ≤ 50).

Output

If “black” team wins output “black”, otherwise output “grimy”.

Samples

input output
1
grimy
4
black





题意:给一个n,两人轮流在1~n的序列中的数前面加上“+”或“-”,black先选择。如果最后的结果是偶数,则black获胜,否则grimy获胜。

解析:看似博弈论,其实可以找到规律的,利用搜索,不难发现:当n = 1, 2时,所有组合全为奇数;当n = 3, 4时,全为偶数;n = 5,6时,全为奇数。。。以此类推,可知每隔两个结果就相反。



AC代码:

#include <cstdio>

int main(){
    int n;
    while(scanf("%d", &n)==1){
        if((n+1)/2 & 1) puts("grimy");
        else puts("black");
    }
    return 0;
}







URAL 1924 Four Imps (博弈论 + 规律)

标签:

原文地址:http://blog.csdn.net/u013446688/article/details/44102555

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!