joj2699

来源:互联网 发布:知到智慧树官网 编辑:程序博客网 时间:2024/06/03 21:06

 2699: 16 and 18


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE1s65536K28565Standard

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 130 310 20 0

Sample Output

181618

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