首页 > 其他 > 详细

GYM - 101147 A.The game of Osho

时间:2018-04-21 13:19:28      阅读:189      评论:0      收藏:0      [点我收藏+]

题意:

  一共有G个子游戏,一个子游戏有Bi, Ni两个数字。两名玩家开始玩游戏,每名玩家从N中减去B的任意幂次的数,直到不能操作判定为输。问谁最终能赢。

题解:

  当Bi为奇数的时候,显然Bi的所有次幂都是奇数,那么答案只需要判断Ni的奇偶性即可。

  那么我们只需讨论Bi为偶数的情况。

  用到了二项展开的一个定理。(B+1-1)^x展开后只有两种形式,即k*(B+1)+1或k*(B+1)+B。所以问题就变成在Ni%(Bi+1)个石子中取1或B个石子。

  Ni%(Bi+1)为B的时候有两种后续状态,0或B-1,所以sg值为2。

技术分享图片
#include <bits/stdc++.h>
using namespace std;
int t;
int g;
int b, n;
int ans;
int main() {
    freopen("powers.in","r",stdin);
    scanf("%d", &t);
    while(t--) {
        ans = 0;
        scanf("%d", &g);
        while(g--) {
            scanf("%d%d", &b, &n);
            if(b&1) ans ^= n&1;
            else {
                int tt = n%(b+1);
                if(tt==b) ans ^= 2;
                else ans ^= tt&1;
            }
        }
        if(ans) puts("1");
        else puts("2");
    }
}
View Code

 

GYM - 101147 A.The game of Osho

原文:https://www.cnblogs.com/Pneuis/p/8900637.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!