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. 7.2 Models -- Defining Models

    一.概述 1. 模型是一个类,它定义了你呈现给用户的数据的属性和行为.用户希望如果他们离开你的应用程序,并返回后(或如果他们刷新页面)看到的任何东西应该被一个model代表. 2. 确保在ember. ...

  2. Linux下安装系统清理软件 BleachBit 1.4

    sudo add-apt-repository ppa:n-muench/programs-ppasudo apt-get updatesudo apt-get install bleachbit

  3. poj1177 Picture 矩形周长并

    地址:http://poj.org/problem?id=1177 题目: Picture Time Limit: 2000MS   Memory Limit: 10000K Total Submis ...

  4. WdatePicker设置日期范围

    设置 结束日期不超过当天日期:设置 开始日期不超过结束日期:设置 开始日期默认显示当月1日的日期,结束日期显示当天日期?<label>开始日期:</label><inpu ...

  5. python 字典(dict)get方法应用

    如果我们需要获取字典值的话,我们有两种方法,一个是通过dict['key'],另外一个就是dict.get()方法. 今天给大家分享的就是字典的get()方法. 这里我们可以用字典做一个小游戏,假设用 ...

  6. 关于函数strtok和strtok_r的使用要点和实现原理(一)【转】

    本文转载自:http://astute11.blog.51cto.com/4404646/1334198 strtok函数的使用是一个老生常谈的问题了.该函数的作用很大,争议也很大.以下的表述可能与一 ...

  7. 解决com.mongodb.MongoException$CursorNotFound: cursor 0 not found on server

    背景 经常需要执行脚本调用Java程序读取mongodb中数据,本来是转为后台进程.偶尔看看日志的简单任务.今天发现程序抛出异常“com.mongodb.MongoException$CursorNo ...

  8. Spring Boot从Controller层进行单元测试

    单元测试是程序员对代码的自测,一般公司都会严格要求单元测试,这是对自己代码的负责,也是对代码的敬畏. 一般单元测试都是测试Service层,下面我将演示从Controller层进行单元测试. 无参Co ...

  9. 使用sublime text3配置c++编译运行

    首先我们可以下载一个Dev-c++,这东西可以自己帮你配置好网上提示的那一大堆奇怪的文件... 网上博客大都在说些什么添加各种编译环境,加入sublime-build什么的..然而作为一个喜欢偷懒的人 ...

  10. ZOJ 2314 Reactor Cooling(无源汇上下界网络流)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题意: 给出每条边流量的上下界,问是否存在可行流,如果存在则输出. ...