HDU 4764-Stone(博弈)

来源:互联网 发布:成都软件学院 编辑:程序博客网 时间:2024/05/01 05:32

Problem Description
Tang and Jiang are good friends. To decide whose treat it is for dinner, they are playing a game. Specifically, Tang and Jiang will alternatively write numbers (integers) on a white board. Tang writes first, then Jiang, then again Tang, etc... Moreover, assuming that the number written in the previous round is X, the next person who plays should write a number Y such that 1 <= Y - X <= k. The person who writes a number no smaller than N first will lose the game. Note that in the first round, Tang can write a number only within range [1, k] (both inclusive). You can assume that Tang and Jiang will always be playing optimally, as they are both very smart students.
 

Input
There are multiple test cases. For each test case, there will be one line of input having two integers N (0 < N <= 10^8) and k (0 < k <= 100). Input terminates when both N and k are zero.
 

Output
For each case, print the winner's name in a single line.
 

Sample Input
1 130 310 20 0
 

Sample Output
JiangTangJiang

题意:

J 和 T 轮流说数字,后一个数字Y 与前一个数字 X 应该符合 1<=Y - X <=k ; 谁说的数字大于等于 N , 则输, J 先。

思路:

简单的博弈题。采用逆推的想法,首先数到 N 和大于 N 的数就输,因为两人都很聪明,则一个数到N-1, 则另一个人就输了,则这个位置叫做必胜位。再往前推,如果有人走到了N-1-1 到 N-1-k 的位置,则另一个人肯定会在 N-1 的位置,则这个人就会输了。则这些个位置是必输点。

样例:N= 10,K= 2

           0 1   2  3  4   5  6   7  8   9  10

          Y  N  N  Y  N  N  Y  N  N  Y   N

可以发现0 位置就是J的比赛结果,必输必赢是周期为(k+1)的循环,所以可以取模。

CODE:

#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <string>#include <cstring>#include <queue>#include <stack>#include <vector>#include <set>#include <map>const int inf=0xfffffff;typedef long long ll;using namespace std;bool check(int n, int k){    return (n%(k+1) == 1);}int main(){    int N,K;    while(~scanf("%d %d", &N, &K),N){        if(check(N, K)) {            printf("Jiang\n");        }        else{            printf("Tang\n");        }    }    return 0;}




0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 公司有人带自己电脑办公怎么办 组装电脑连不上网怎么办 显卡玩不起吃鸡怎么办 u盘内存是假的怎么办 新买的电脑应该怎么办 海尔一体机电脑开不开机怎么办 苹果笔记本系统坏了怎么办 苹果笔记本电脑电池坏了怎么办 苹果笔记本电脑屏幕坏了怎么办 平板开关键坏了怎么办 平板电脑电池坏了怎么办 平板电脑充电口坏了怎么办 平板电脑系统坏了怎么办 平板电脑充电器坏了怎么办 平板电脑触摸屏坏了怎么办 平板电脑关不了机怎么办 平板电脑触摸屏没反应怎么办 平板电脑声音太小怎么办 平板电脑频碎了怎么办? 淘宝直播展示频道排后怎么办 网店头像改不了怎么办 被骗了7500追不回来怎么办 steam中国版原来的游戏怎么办 老公买驾照被骗妻子应该怎么办 被淘密码骗了怎么办 逛街手机没电了怎么办 电脑登入密码忘了怎么办 晚上睡不好觉经常做梦怎么办 开淘宝店开始零销量怎么办 淘宝店开直通车后销量怎么办 淘宝直播一开始直播没人该怎么办 淘宝店铺访客数据下滑怎么办 2个ctrl键都失灵怎么办 淘宝上搜索不到很久以前订单怎么办 关键词找不到了是不是被降权怎么办 购买小程序关键词想退款怎么办? 浏览器审查元素不拆分关键词怎么办 拼多多商品想重新编辑怎么办 新开店铺没有销量怎么办 新开的店铺没有销量怎么办 淘宝的商品权重下降是怎么办