1924. Four Imps-博弈论

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
Problem Author: folklore
Problem Source: Ural Regional School Programming Contest 2012
Tags: none   (
hide tags for unsolved problems
)



题意:
grimy和black 在 1到n的数字中间轮流插入+或 - ,grimy的目标是使得最后运算结果是奇数,black是偶数

解题思路:
试试就会发现,如果1到n的和是偶数,假如把第x个加号变为减号,那么运算结果就会减去2倍的第x+1个数,一个偶数减去一个偶数,结果还是偶数,一个偶数减去n个偶数,结果还是偶数,所以结果只与1到n的和的奇偶性有关。


代码
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

const int maxn = 1000+10;


int main()
{
    int n,m;
    scanf("%d",&n);
    int ans = 0;
    for(int i = 1;i<=n;++i){
        ans += i;
    }
    if(ans%2==0) printf("black");
    else printf("grimy");
    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值