题目链接:https://nanti.jisuanke.com/t/31000

题意:有N堆石子(N为大数),每堆的个数按一定方式生成,问先手取若干堆进行尼姆博弈,必胜的方式有多少种。

题解:因为 k < 4096,所以出现的数最多只有4096个,对每个数字只考虑出现奇/偶次进行dp,答案是所有不等于0的dp值的和。然后如果一个数字出现x次,它对自己出现奇数次的方案数和偶数次的方案数贡献都是乘上2 ^ (x - 1),每个数字的贡献都是2 ^ (x - 1) 总贡献就是2 ^ (N - ∑(vis[i]))。大数可以一边读入一边取模。

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 1e7 + ;
const int MAXM = 2e6 + ;
const ll mod = 1e9 + ; bool vis[];
int dp[][];
vector<int>vec;
int f[]; ll pow_mod(ll a, ll n) {
ll ans = ;
while(n) {
if(n & ) ans = ans * a % mod;
a = a * a % mod;
n >>= ;
}
return ans;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
ll ans = ;
char ch;
int len = ;
int n = 1e9;
while() {
scanf("%c", &ch);
if(ch == ' ') break;
ans = pow_mod(ans, );
if(len == ) ans = ;
ans = ans * (1ll << (ch - '')) % mod;
if(len <= ) {
if(len == )
n = ;
n = n * + ch - '';
len++;
}
}
int x;
scanf("%d", &x);
int temp = x;
int a, b, c, d, e, k;
scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
vec.push_back(x);
vis[x] = true;
for(int i = ; i <= ; i++) {
int x1 = 1ll * a * i * i % k * i * i % k;
int x2 = 1ll * b * i * i % k * i % k;
int x3 = 1ll * c * i * i % k;
int x4 = 1ll * d * i;
x = (x1 + x2 + x3 + x4 + e - ) % k + ;
f[i] = x;
}
int all = ;
while(all < n) {
all++;
int now = f[temp];
if(!vis[now]) {
vis[now] = true;
vec.push_back(now);
temp = now;
} else break;
}
int sz = vec.size();
dp[][] = ;
int pre = , now = ;
for(int i = ; i <= sz; i++) {
swap(pre, now);
int num = vec[i - ];
for(int j = ; j < ; j++) dp[now][j] = dp[pre][j];
for(int j = ; j < ; j++) {
dp[now][j ^ num] += dp[pre][j];
if(dp[now][j ^ num] >= mod) dp[now][j ^ num] -= mod;
}
}
ll sum = ;
for(int i = ; i < ; i++) {
sum += dp[now][i];
if(sum >= mod) sum -= mod;
}
ll inv = pow_mod(, sz);
inv = pow_mod(inv, mod - );
ans = ans * inv % mod;
ans = ans * sum % mod;
printf("%lld\n", ans);
return ;
}

ACM-ICPC 2018 南京赛区网络预赛 K. The Great Nim Game(博弈)的更多相关文章

  1. ACM-ICPC 2018 南京赛区网络预赛B

    题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...

  2. 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)

    G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K   During tea-drinking, princess, amongst other t ...

  3. 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)

    A. An Olympian Math Problem 54.28% 1000ms 65536K   Alice, a student of grade 66, is thinking about a ...

  4. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall

    题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K   Feeling hungry, a cute hamster decides to o ...

  5. ACM-ICPC 2018 南京赛区网络预赛

    轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K   Alice, a student of g ...

  6. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

    262144K   There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v ...

  7. ACM-ICPC 2018 南京赛区网络预赛(12/12)

    ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem 计算\(\sum_{i=1}^{n-1}i\cdot i!(MOD\ n)\) \(\sum_{i ...

  8. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  9. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

随机推荐

  1. [Python3 填坑] 004 关于八进制

    目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 问题的由来 2.2 问题的解决 2.2.1 先说结论 2.2.2 八进制的用途 2.2.3 少废话,上例子 1. print( 坑的信息 ...

  2. linux利用crontab添加定时任务详解

    crontab 作用:添加,查询,删除系统计划任务的指令. [root@localhost ~]# crontab [选项]选项:    -e:    编辑crontab定时任务    -l:    ...

  3. Oracle 查询id相同多个数据取一条

    涉及场景 需要查出同一ID下 COLUMN_A字段为数值型的 多条数据 只去COLUMN_A为最小值的那条 SELECT * FROM (SELECT A.ID, A.COLUMN_A, ROW_NU ...

  4. AtCoder AISing Programming Contest 2019 Task D. Nearest Card Game

    题目分析在代码注释里. int main() { #if defined LOCAL && !defined DUIPAI ifstream in("main.in" ...

  5. java获取单张网页中img标签中的src

    /** * 得到网页中图片的地址 */ public static List<String> getImgStr(String htmlStr) { List<String> ...

  6. 运算符优先级 以及 && (逻辑与) 和||(逻辑或)的优先级:

    运算符优先级(从高到低列出) 运算符 描述 . [] () 字段访问.数组下标.函数调用以及表达式分组 ++ -- - ~ ! delete new typeof void 一元运算符.返回数据类型. ...

  7. php 连接webservice接口

    首先谢谢前人, 引用:https://www.cnblogs.com/xbxxf/p/10103430.html 本来说对接接口,我以为是一扮curl接口形式,结果最后给接口锝时候才告诉我是webse ...

  8. EasyUI中的重要的控件和属性

    data-options: precision:2     保留2为小数 validType:

  9. linux环境下安装python3的方法(转)

    Linux 安装python3.7.0   我这里使用的时centos7-mini,centos系统本身默认安装有python2.x,版本x根据不同版本系统有所不同,可通过 python --V 或 ...

  10. lua table vs closure

    最近在重构自己写的框架中的定时器模块,需要把回调函数保存起来,大概如下: function timer_mgr:save_timer( this,callback ) return { this = ...