URAL 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

题意:给一个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;
}
时间: 2024-10-12 07:55:45

URAL 1924 Four Imps (博弈论 + 规律)的相关文章

URAL 2070 Interesting Numbers (找规律)

题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然后用总数减掉就好.打个表,找找规律,你会发现, 这些数除外的数都是素数的素数次方,然后就简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include &

POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律

http://poj.org/problem?id=1740 这个博弈一眼看上去很厉害很高大上让人情不自禁觉得自己不会写,结果又是找规律-- 博弈一般后手胜都比较麻烦,但是主要就是找和先手的对应关系,依然看了题解-- 如果所有石头堆两两配对的话后手对先手的每一步都可以对应走一步,那么此时后手必胜. 如果不是两两配对,先手可以通过一次操作使石头堆两两配对,此时的两两配对局面面对的是后手,所以先手必胜. 不是两两配对时的操作:首先将所有非配对推按大小排序(只有一堆直接取没就可以了): 然后显然不配对

URAL 2065 Different Sums (找规律)

题意:构造一个数列,使得它们的区间和的种类最少,其中数列中不同的数的数目不少于k. 析:我们考虑0这个特殊的数字,然后0越多,那么总和种类最少,再就是正负交替,那么增加0的数量. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath&g

POJ2505 A multiplication game 博弈论 找规律

http://poj.org/problem?id=2505 感觉博弈论只有找规律的印象已经在我心中埋下了种子... 题目大意:两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9的数,然后Ollie再乘以一个2-9的数,直到谁先将p乘到p>=n时那个人就赢了,而且轮到某人时,某人必须乘以2-9的一个数. 题目大意来源http://blog.csdn.net/jc514984625/article/details/71157698 因为谷歌翻译太难懂了,所以总是找题解找题目大

URAL 1180. Stone Game (博弈 + 规律)

1180. Stone Game Time limit: 1.0 second Memory limit: 64 MB Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition

【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> //#include<set> //#include<cstring> //using namespace std; //bool vis[16]; //int n,SG[16][1<<16]; //int sg(int x,int moved) //{ // if(SG

URAL 1295 Crazy Notions 数学 找规律

1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of the atmospheric electricity has led to the depressurizati

URAL 1295. Crazy Notions(数学啊 &amp; 找规律)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1295 1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of th

URAL 1224. Spiral (规律)

1224. Spiral Time limit: 1.0 second Memory limit: 64 MB A brand new sapper robot is able to neutralize mines in a rectangular region having integer height and width (N and M respectively). Before the robot begins its work it is placed near the top le