NYOJ 23, Take Stones (Bash Game)

take stones (1)

Time Limit: 3000 ms | Memory Limit: 65535 KB
Difficulty: 2
describe
One day, TT was idle and bored in the bedroom, and played a game of fetching stones with his bedmate. Due to limited conditions, he/they used Wangzai's small steamed buns as stones. The rules of the game are this. There is a pile of stones, the number of which is N (1<=N<=1000000), two people take turns to take out several of them, and at most M each time (1<=M<=1000000), the first to take out the stones victory. We know that TT and his/her roommate are very smart, so if TT takes first, will he/she win the game?
enter
The first line is a positive integer n, which means there are n groups of test data. The
input has less than 1000 groups of data, each group of data has one line, and there are two numbers N and M, separated by spaces.
output
For each set of data, output one row. If the TT taken first can win the game, output "Win", otherwise output "Lose" (quotes are not output)
sample input
2
1000 1
1 100
Sample output
Lose
Win

----------------------------------------------------------------------------------------------------

Bash game: There are only a pile of n items, and two people take turns to take items from the pile, and it is stipulated that at least one item is taken at a time, and at most m items are taken. The one who takes the light in the end wins.

    Obviously, if n=m+1, since only m items can be taken at most at a time, no matter how many items are taken by the first taker, the second taker can take the remaining items at one time, and the latter wins. So we found the rule of how to win: if
n=(m+1)*r+s, (r is any natural number, s≤m), then the first taker will take s items, if the second taker takes k (≤m), then the first taker will take m+1-k, and the result will be (m+1)(r-1) remaining. If this method is maintained in the future, then the first taker will definitely win. In short, to keep the multiple of (m+1) left for the opponent, you can finally win. Then at this time, as long as n%(m+1)!=0, the first taker will definitely win .


AC code:

#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int N,M;
cin>>N>>M;
                if(N%(M+1)!=0)
cout<<"Win"<<endl;
else
cout<<"Lose"<<endl;
}
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938291&siteId=291194637