CJOJ take stones children problem-solving report

【Problem Description】

L T is small and small stones taken child game, given an integer n represents the total number of stones children, given an integer k table
shows a maximum number of stones can take children, small L upper hand, each could get take 1 ~ k a stone child, they will always have a
personal take s last pieces of stone child, so that the number of remaining stones child is 0, the last remaining stone away children who won
victory, the other a person fail.
Small T is very smart, extremely small L (Baldy (escape)) clever, please determine whether the small T can win.

[Enter]

The first line T represents an integer number of data sets, each row next two integers line T n, k meaning given description.

[Output]

For each test, output "YES" or "NO" (without the quotes), representing small T is to win.
[O] Sample
the Input
2
2. 1
10. 4
the Output
YES
YES

answer

Think about the last step to consider
considering most small L desperate situation, it is in any case only a few remaining stone within the block k, namely k + 1 blocks, if only k + 1 block, then no matter how this person take, another person can take complete;
that is, who can make stones remaining k + 1 block who is the winner, the same token, in order to allow the remaining k + 1 stone blocks long to get k + 1 + k +1, will be able to take k + 1;
therefore, who got multiple k + 1, who is the winner
so long as it is determined that the relation n k + 1, will be able to start the determination result (of course, two people have enough smart case)
if n is a multiple of k + 1, how sure can not win the upper hand (as long as no floating FLAC)

Code

#include <cstdio>
#define ll long long
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
inline unsigned ll read(){
    unsigned ll x=0;char c=getchar();
    while (c<'0'||c>'9') c=getchar();
    while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return x;
}
unsigned ll n,k;

void init(){
    n=read(),k=read();
}

void doit(){
    if (n-n/(k+1)*(k+1)) puts("NO");//n-n/(k+1)*(k+1)=n%(k+1),前者跑得比后者快一点点
    else puts("YES");
}

signed main(){
    file("tstones");
    int T=read();
    while (T--){
        init();
        doit();
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/ancer/p/11294898.html