Question
Total Submission (s): 0 Accepted Submission (s): 0
Problem DescriptionTang 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 shoshould 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 transaction SIVE ). you can assume that Tang and Jiang will always be playing optimally, as they are both very smart students.
InputThere 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.
OutputFor each case, print the winner's name in a single line.
Sample Input
1 130 310 20 0
Sample Output
JiangTangJiang
Question
Although the game is simple, it is really difficult for me to keep off the dregs of the game, helpless, even half a day finally wrote the code =. =
First, let's explain the meaning of the question. jiang and tang are two good friends playing a digital game. Give N to k. N represents the upper limit, that is, two people cannot exceed N in the game; k Represents the selectability. According to the meaning of the question, when writing numbers, the new digit Y must be in the range of [1 + X, k + X]. So let's start with the example:
N = 1, k = 1:
According to the game regulations, tang starts to say numbers. Because the game rules require that numbers must be greater than or equal to 1, tang can only report 1. However, due to rule requirements, whoever wants to give his number a value greater than or equal to N will lose. Therefore, tang must lose, so the winner is
N = 30, k = 3:
It may be a bit difficult, but I hope everyone can take a look: If jiang wants to win the game, then he must force tang to say 30. There is no doubt that jiang has to say 29 first to win the competition. However, from the perspective of tang, tang is not stupid enough to directly deliver a victory to the opposite side, so he must prevent jiang from saying 29, so he cannot say 26, or jiang will have a chance. Next, follow these steps:
If jiang is about to grab 25, tang cannot say 22.
If jiang is about to grab 21, tang cannot say 18.
If jiang is about to grab 17, tang cannot say 14.
When jiang is about to grab 13, tang cannot say 10.
If jiang is about to grab 9, tang cannot say 6.
If jiang is about to grab 5, tang cannot say 2.
Okay, stop!
Rule, rule! Did you see it? As long as tang does not say 2 or above, tang will win.
Tang can be called "1 ".
Therefore, tang won.
N = 10, k = 2:
Or just now:
Suppose jiang wants to win the game:
Jiang needs to get 9, tang cannot say 7.
If jiang is about to grab 6, tang cannot say 4.
If jiang is about to grab 3, tang cannot say 1.
Therefore, tang cannot be a big number. tang loses and jiang wins.
N, k so we can see a rule. Let's look at the code in detail. Sample Code
/*****@Polo-shen**/#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <map>using namespace std;#define DBG 0#define ShowLine DBG && cout<<__LINE__<<">>| "#define dout DBG && cout<<__LINE__<<">>| "#define write(x) #x" = "<<(x)<<" "#define awrite(array,num) #array"["<<num<<"]="<<array[num]<<" "#ifndef min#define min(x,y) ((x) < (y) ? (x) : (y))#endif#ifndef max#define max(x,y) ((x) > (y) ? (x) : (y))#endifint main(){ int N,k; while (cin>>N>>k && (N && k)){ int sum=N-1; int tmp=sum%(k+1); if (tmp!=0){ cout<<"Tang"<<endl; } else { cout<<"Jiang"<<endl; } } return 0;}