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. wordpress防止网站被镜像四个方法

    第一种:拆分域名链接与镜像站比对,然后用img标签src空值触发onerror来执行js比对,比对失败则跳转回源站.代码如下:(复制粘贴到主题的functions.php最后一个?>之前,代码出 ...

  2. nmon监控Linux服务器系统资源

    本文转自:http://www.cnblogs.com/hyzhou/archive/2011/12/29/2305860.html 在实际的测试过程中,Loadrunner监控Linux系统资源不太 ...

  3. 如何把js的循环写成异步的

    针对这里的问题:深入理解node.js异步编程:基础篇https://cnodejs.org/topic/533d6edbc2621e680800e0ea 这一节有一个代码:###4.1 Node.j ...

  4. 通用Linux内核优化配置

    通用Linux内核优化配置 针对CentOS6.CentOS7.Redhat6.Redhat7等系统 net.ipv4.ip_forward = net.ipv4.conf. net.ipv4.con ...

  5. SpringMVC小demo解析

    第一次实际接触SpringMVC,之前在教程网站上看得是概念性的. SpringMVC是属于Java框架SSM中的一环 在做了一个小demo后发现原来编程如此简单. 首先建立动态网页项目(Dynami ...

  6. 51Nod 1737 配对(树的重心)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1737 题意: 思路: 树的重心. 树的重心就是其所以子树的最大的子树结点 ...

  7. cocos2d-js入门二 环境搭建二

    电脑升级到WIN10后,cocos  code IDE安装不成功. 于是搭建新的环境JetBrainsWebStorm+chrome+JetBrains IDE Support,其中JetBrains ...

  8. python 堆栈

    class Node: #堆栈链结节点的声明 def __init__(self): self.data= #堆栈数据的声明 self.next=None #堆栈中用来指向下一个节点 top=None ...

  9. JavaScript--语法2--语句结构

    JavaScript--语句结构 一.心得 判断的时候常量放左边java中switch只支持四种类型,javaScript是弱类型,所有的都支持. 显示方法: 77 // alert("x= ...

  10. (GoRails)ActionCable如何用Redis + 菜鸟redis教程

    视频: https://gorails.com/episodes/how-actioncable-uses-redis?autoplay=1 原理PubSub, 你进入一个频道,然后就能接收,和发布信 ...