题意  Alice和Bob在玩一个游戏,Alice先手。

每次一个人可以从一堆式子中拿走任意数量(不超过m)的式子。

取走最后一颗式子的人胜利。

当一个取完某一步的时候剩下的石子数量的二进制表示中1的个数为奇数时,这个人直接输。

$n <= 5* 10^{8}, m <= 50$

考虑博弈

我们可以用一个01数组来表示之前50步的胜败状态。

因为m <= 50,可以直接用一个long long 来替换掉这个数组。

求二进制表示中1的个数的时候,采用预处理的方式,拆成前16位和后16位就可以了。

其他都是博弈的老套路。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 1e6 + 10; int pre[N]; class ThueMorseGame {
public:
string get(int n, int m){
LL all = (1LL << m) - 1;
LL cnt = all;
rep(i, 0, (1 << 16) - 1) pre[i]= __builtin_popcount(i);
rep(i, 0, n) cnt = ((cnt << 1) & all) | (((pre[i >> 16] + pre[i & ((1 << 16) - 1)]) & 1) || (cnt ^ all));
return cnt & 1 ? "Alice" : "Bob";
}
};

TopCoder SRM 701 Div2 Problem 900 ThueMorseGame(博弈+预处理)的更多相关文章

  1. TopCoder SRM 660 Div2 Problem 1000 Powerit (积性函数)

    令$f(x) = x^{2^{k}-1}$,我们可以在$O(k)$的时间内求出$f(x)$. 如果对$1$到$n$都跑一遍这个求解过程,时间复杂度$O(kn)$,在规定时间内无法通过. 所以需要优化. ...

  2. TopCoder SRM 301 Div2 Problem 1000 CorrectingParenthesization(区间DP)

    题意  给定一个长度为偶数的字符串.这个字符串由三种括号组成. 现在要把这个字符串修改为一个符合括号完全匹配的字符串,改变一个括号的代价为$1$,求最小总代价. 区间DP.令$dp[i][j]$为把子 ...

  3. Topcoder SRM 618 Div2 --900

    题意:给定两个NxN的棋盘,每个棋盘都有一个‘车’的摆放状态,问进行若干次交换,能否使棋盘1变为棋盘2. 交换规则:每次选两个‘车’,坐标分别为(r1,c1),(r2,c2),如果r1<r2并且 ...

  4. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  5. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  6. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  7. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

  8. topcoder SRM 628 DIV2 BracketExpressions

    先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...

  9. topcoder SRM 628 DIV2 BishopMove

    题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...

随机推荐

  1. OwinStartupAttribute出错

    尝试加载应用时出现了以下错误.- 找不到包含 OwinStartupAttribute 的程序集.- 找不到包含 Startup 或 [AssemblyName].Startup 类的程序集.若要禁用 ...

  2. 【php】对象的比较

    对象的比较 相等的比较 ==当使用比较运算符(==)比较两个对象变量时,比较的原则是:如果两个对象的属性和属性值 都相等,而且两个对象是同一个类的实例,那么这两个对象变量相等. 全等的比较 ===如果 ...

  3. yagmail 邮箱的使用

    文章来源:GITHub:https://github.com/kootenpv/yagmail 安装 pip3 install yagmail pip3 install keyring 简单例子 im ...

  4. GPIO程序在PC上的模拟学习

    #include <stdio.h> #include <malloc.h> #include <memory.h> typedef struct gpio { i ...

  5. POJ 1791 Parallelogram Counting(求平行四边形数量)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  6. x mod a=r(N对a,r)

    //模数不一定互质,互质才可以用孙子定理. /* https://blog.csdn.net/zmh964685331/article/details/50527894 uu遇到了一个小问题,可是他不 ...

  7. 安装lwqq

    $ git clone https://github.com/xiehuc/pidgin-lwqq.git $ cd pidgin-lwqq/ $ sudo apt-get install cmake ...

  8. BZOJ 2687: 交与并

    答案存在于 1.两个互相包含的区间 2.两个互不包含的区间 决策单调性显然 但是这代码很精妙啊,并不知道这个为什么能这样写 #include<cstdio> #include<alg ...

  9. C++ 获取网页源码码的操作

    #include <stdio.h>#include <windows.h>#include <wininet.h>#pragma comment(lib,&quo ...

  10. Leetcode28--->字符串的匹配(KMP)

    题目: 题目的本质是给定两个字符串str1,str2,求str1中的str2串开始的地方,即字符串的匹配,KMP算法 思路:时间复杂度为O(m + n),空间复杂度为O(n),原串的长度为m,子串的长 ...