joj2699

 2699: 16 and 18

Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
1s 65536K 285 65 Standard

16 and 18 are good friends. They are playing a game.

The rules are as following:

(1) 16 and 18 will give numbers in turn. At first 16, then 18, and then 16...
(2) If the previous one give a number A, the number the next one gives, namely B, must satisfy that
1 <= B - A <= k.
(3) Who first gives the number larger than or equal to N will lose the game.
(4) The game always starts with 16, and he can only give a number from [1, k] in the first round.
(5) Suppose that both of them will try their best to win.

Input

In each line, there will be two integers N (0 < N <= 100, 000, 000) and k (0 < k <= 100). Input terminates when N = k = 0

Output

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

Sample Input

1 1
30 3
10 2
0 0

Sample Output

18
16
18

Problem Source: homeboy





博弈问题详细情况可以看我转载的博弈问题总结



#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k),n&&k)
    {
        if((n-1)%(k+1)==0)cout<<18<<endl;
        else cout<<16<<endl;
    }
    return 0;
}


This problem is used for contest: 168  190 

你可能感兴趣的:(joj2699)