F - Stone-----(2015 summer training #11)

来源:互联网 发布:hadoop 数据存储 编辑:程序博客网 时间:2024/04/29 22:14

F - Stone
时限:1000MS     内存:32768KB     64位IO格式:%I64d & %I64u

问题描述

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. 
 

输入

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. 
 

输出

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

样例输入

1 130 310 20 0
 

样例输出

JiangTangJiang
 

分析:经典的博弈问题。首先考虑一下必胜的情况,当变成什么状况时,无论对手怎么做,我都是赢得情况。拿10 2这组数据,当我拿到9时,我就必胜。继续前推,当我拿到6时,我也是必胜。再推,我拿到3时必胜。。。。。。。。。。。。这样就能总结出公式。


CODE:

#include <iostream>using namespace std;int main(){    long long n,k;    while(cin>>n>>k&&(n||k)){        if((n-1)%(k+1)==0)            cout<<"Jiang"<<endl;        else            cout<<"Tang"<<endl;    }    return 0;}



0 0