URAL 1924 Four Imps (博弈论 + 规律)
来源:互联网 发布:js比较两个数值大小 编辑:程序博客网 时间:2024/05/16 05:04
1924. Four Imps
Time limit: 1.0 second
Memory limit: 64 MB
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
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;}
0 0
- URAL 1924 Four Imps (博弈论 + 规律)
- 1924. Four Imps-博弈论
- 即时通信(IMPS)
- hud1517 博弈论(找规律)
- URAL 1224. Spiral (规律)
- URAL 1639 Chocolate 2 (博弈论)
- HDU 5512 Pagodas (博弈论、找规律)
- ural 1260(找规律)
- URAL 1502. Domino Dots (找规律)
- URAL 1180. Stone Game (博弈 + 规律)
- URAL 1225-Flags(规律递推)
- hdu 4664 Triangulation(博弈论 sg找规律打表)
- hdu Calendar Game (博弈论奇偶性找规律)
- hdu 1525 Euclid's Game(博弈论找规律)
- hdu 1564 paly a game(博弈论找规律)
- URAL 1209. 1, 10, 100, 1000... (规律 + 二分)
- URAL - 1117 Hierarchy(找规律)
- POJ 2368|URAL 1023|Buttons|博弈论
- Android自动化测试(UiAutomator)
- java保留两位小数
- FTMD_DEMO
- P2P模式分析之资金池与第三方托管
- Centos 更换本地源,搭建openstak本地源
- URAL 1924 Four Imps (博弈论 + 规律)
- Android ProgressBar自定义图片进度,自定义渐变色进度条
- 2014年娜迦CM赛 第一题(原帖:记一次算法逆向)
- Tab 模块 (二)
- TypedArray和obtainStyledAttributes使用
- sql个人总结3
- Java实现几种常见排序方法
- linux下zip打包与解压
- Android开源项目--分类汇总