Stone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2204    Accepted Submission(s): 1553


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 1
30 3
10 2
0 0 

Sample Output

Jiang
Tang
Jiang

题意:Tang和Jiang两个人写数字,Tang先写,每次前一个人和后一个人写的数字分别为x,y;满足:1<=y-x<=k。在第一轮中,Tang写的数字在1~k之间,谁写的数字不小于n就输了。

思路:可以看做是每轮n变成n-x-y,问最后一轮n是否等于1 。如果等于1的话则Jiang获胜。

可以转化为巴什博弈问题:有n-1个石子,每次至少取1个,最多取k个,问谁能拿到最后一个石子

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
using namespace std;
const int maxn=1e6+10;
int main()
{
int n,k;
while(cin>>n>>k&&n&&k)
{
if((n-1)%(k+1)==0)
cout<<"Jiang"<<endl;
else
cout<<"Tang"<<endl;
}
return 0;
}

HDU 4764:Stone(巴什博弈)的更多相关文章

  1. hdu 4764 Stone (巴什博弈,披着狼皮的羊,小样,以为换了身皮就不认识啦)

    今天(2013/9/28)长春站,最后一场网络赛! 3~5分钟后有队伍率先发现伪装了的签到题(博弈) 思路: 与取石头的巴什博弈对比 题目要求第一个人取数字在[1,k]间的某数x,后手取x加[1,k] ...

  2. HDU 4764 Stone (巴什博弈)

    题意 Tang和Jiang玩石子游戏,给定n个石子,每次取[1,k]个石子,最先取完的人失败,Tang先取,问谁是赢家. 思路 比赛的时候想了不久,还WA了一次= =--后来看题解才发现是经典的巴什博 ...

  3. HDU 4764 Stone(巴什博奕)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  4. 2013长春网赛 1006 hdu 4764 Stone(巴什博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 题意:Tang 和 Jiang 玩一个游戏,轮流写下一个数,Tang先手,第一次Tang只能写[ ...

  5. 题解报告:hdu 4764 Stone(巴什博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 Problem Description Tang and Jiang are good frie ...

  6. HDU 4764 Stone(博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 题目大意:Tang和Jiang玩石子游戏,给定n个石子,每次取[1,k]个石子,最先取完的人失败 ...

  7. HDU 4764 Stone (2013长春网络赛,水博弈)

    Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. HDU 4388 Stone Game II {博弈||找规律}

    Stone Game II Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. HDU 1847 【巴什博弈】

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  10. HDU 2897 经典巴什博弈

    从n个石子中每次取p~q个,求先手能否获胜 可以先列举一部分数据,然后观察可得总是在p+q中循环,所以只要用n对p+q取模就好了 #include <cstdio> #include &l ...

随机推荐

  1. python16_day36【爬虫1】

    一.requests 1. GET请求 # 1.无参数实例 import requests ret = requests.get('https://github.com/timeline.json') ...

  2. curl获取远程文件内容

    curl获取远程文件内容 ** 获取远程文件内容 @param $url 文件http地址 * function fopen_url($url) { if (function_exists(& ...

  3. PHImageManager 获取图片模糊

    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.synchronous = true; o ...

  4. linux第五周

    第五周 给MenuOS增加time和time-asm命令 更新menu代码到最新版 在main函数中增加MenuConfig 增加对应的Time函数和TimeAsm函数 make rootfs 使用g ...

  5. 20145325张梓靖 《Java程序设计》第9周学习总结

    20145325张梓靖 <Java程序设计>第9周学习总结 教材学习内容总结 JDBC Java语言访问数据库的一种规范,是一套API.JDBC (Java Database Connec ...

  6. #/bin/sh参数-e的含义

    注:本博客欢迎转载和引用,但请保留原作者信息! 一.背景 今天遇到一个诡异的问题,一旦脚本中判断$?为非零,那么脚本就会自动退出的情况,仔细调试脚本的逻辑,并没有发现错误,因此作此文 二.解决 既然要 ...

  7. Thread.Start和Delegate.BeginInvoke 以及Control.BeginInvoke

    Thread.Start starts a new OS thread to execute the delegate. When the delegate returns, the thread i ...

  8. 使用SpringBoot发送邮件

    最后发送成功后,感觉SpringBoot真的很强大. http://www.ykmimi.com/email ↑待加入email输入的重载(可以不上传文件或可以不填写主内容) ↑待加入邮箱RegExp ...

  9. HDU 1166 敌兵布阵(线段树 or 二叉索引树)

    http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N<=50000),表示敌人有 ...

  10. 爬虫模拟登陆之formdata表单数据

    首先HTTP协议是个无连接的协议,浏览器和服务器之间是以循环往复的请求回复来交互的,交互的形式是以文件形式来进行的.比如在chrome开发者工具network中看到了 每一行是一个文件,又文件大小啊, ...