F - Stone-----(2015 summer training #11)
2015-08-14 13:42
411 查看
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.
样例输入
样例输出
分析:经典的博弈问题。首先考虑一下必胜的情况,当变成什么状况时,无论对手怎么做,我都是赢得情况。拿10 2这组数据,当我拿到9时,我就必胜。继续前推,当我拿到6时,我也是必胜。再推,我拿到3时必胜。。。。。。。。。。。。这样就能总结出公式。
CODE:
时限: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 1 30 3 10 2 0 0
样例输出
Jiang Tang Jiang
分析:经典的博弈问题。首先考虑一下必胜的情况,当变成什么状况时,无论对手怎么做,我都是赢得情况。拿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; }
相关文章推荐
- HDU4300-Clairewd’s message-KMP
- E - Theme Section-----(2015 summer training #11)
- D - Cut the Cake----(2015 summer training #11)
- error: linker command failed with exit code 1 (use -v to see invocation)
- J - A Bit Fun-----(2015 summer training #9)
- SGU183 Painting the balls(DP+优化)
- D - Minimum palindrome----(2015 summer training #9)
- C - We Love MOE Girls-----(2015 summer training #9)
- B - Median-----(2015 summer training #8(Qualifying))
- Could not connect to '10.7.100.182' (port 22): Connection failed
- HIT 2060 Fibonacci Problem Again
- LeetCode Factorial Trailing Zeroes
- LeetCode Factorial Trailing Zeroes
- epoll_create, epoll_ctl和epoll_wait
- 2015 Multi-University Training Contest 2(hdu 5300 - hdu 5309)
- Clock Skew , Clock Uncertainty和 Period
- libvirtError: no connection driver available for qemu:///system 解决办法
- 2015 Multi-University Training Contest 8 hdu 5384 Danganronpa
- tools:context=".MainActivity的作用
- 使用Grails快速开发Web应用程序