题意:有n堆火柴,选择连续若干堆火柴进行Nim游戏,求让先手胜的选择方案数。

思路:让先手胜等同于这些数的异或值不同于0,不妨转化为求让先手败的方案数。此时记录一个前缀的异或和val[i],那么答案就是count({i,j})(0<=i<j<n,val[i]=val[j])+count(i)(val[i]=0)。直接map统计可能超时,不妨考虑离线做,把val数组sort一下答案就不难得到了,不要忘记最后用总方案数减一下。

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <stdexcept>
#include <utility> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define mem_1(a) memset(a, -1, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep_up0(a, b) for (int a = 0; a < (b); a++)
#define rep_up1(a, b) for (int a = 1; a <= (b); a++)
#define rep_down0(a, b) for (int a = b - 1; a >= 0; a--)
#define rep_down1(a, b) for (int a = b; a > 0; a--)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt5(name, a, b, c, d, e) name(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0): a(a), b(b), c(c), d(d), e(e) {}
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pchr(a) putchar(a)
#define pstr(a) printf("%s", a)
#define sstr(a) scanf("%s", a)
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d%d", &a, &b)
#define sint3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define pint(a) printf("%d\n", a)
#define test_print1(a) cout << "var1 = " << a << endl
#define test_print2(a, b) cout << "var1 = " << a << ", var2 = " << b << endl
#define test_print3(a, b, c) cout << "var1 = " << a << ", var2 = " << b << ", var3 = " << c << endl
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a) typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {-, , , , , -, , - };
const int maxn = 3e4 + ;
const int md = ;
const int inf = 1e9 + ;
const LL inf_L = 1e18 + ;
const double pi = acos(-1.0);
const double eps = 1e-; template<class T>T gcd(T a, T b){return b==?a:gcd(b,a%b);}
template<class T>bool max_update(T &a,const T &b){if(b>a){a = b; return true;}return false;}
template<class T>bool min_update(T &a,const T &b){if(b<a){a = b; return true;}return false;}
template<class T>T condition(bool f, T a, T b){return f?a:b;}
template<class T>void copy_arr(T a[], T b[], int n){rep_up0(i,n)a[i]=b[i];}
int make_id(int x, int y, int n) { return x * n + y; } int g, s, n, w, a[], nim[]; void init() {
g = s;
rep_up0(i, n) {
a[i] = g;
if (a[i] == ) {
a[i] = g = w;
}
if (g % == ) {
g /= ;
}
else g = (g / ) ^ w;
}
} int main() {
//freopen("in.txt", "r", stdin);
int T;
cin >> T;
while (T --) {
cin >> n >> s >> w;
init();
nim[] = a[];
rep_up0(i, n - ) nim[i + ] = nim[i] ^ a[i + ];
sort(nim, nim + n);
LL ans = ;
rep_up0(i, n) {
if (nim[i] != ) break;
ans ++;
}
LL c = ;
nim[n] = -;
rep_up0(i, n) {
if (nim[i] != nim[i + ]) {
ans += c * (c - ) / ;
c = ;
}
else c ++;
}
cout << (LL)n * (n + ) / - ans << endl;
}
return ;
}

最新文章

  1. 使用 jQuery &amp; CSS3 实现优雅的手风琴效果
  2. override与overload的区别
  3. 接入多家ERP厂商,美团点评餐饮高速路开启
  4. 如何用ssh挂载远程目录
  5. 张艾迪(创始人):发明整个世界+224C个国家
  6. linux服务之drbd
  7. 使用script的src实现跨域和类似ajax效果
  8. leetcode Binary Search Tree Iterator python
  9. 2 kNN-K-Nearest Neighbors algorithm k邻近算法(二)
  10. C#-循环滚动字幕,timer,从左至右,从右至左,暂停---ShinePans
  11. 3. Longest Substring Without Repeating Characters - 最长无重复字符子串-Medium
  12. Angular 非父子组件间的service数据通信
  13. Vue--学习过程中遇到的坑
  14. python 查找日志关键字
  15. 【EMV L2】2CS.001.00 ~ 2CS.007.00
  16. Mac各种数据库安装和启动【笔记】
  17. zabbix监控URL
  18. logstash配置白名单决定去哪个index
  19. Tomcat基本
  20. Linux打开文件设置

热门文章

  1. 6.表单提交,input键盘变搜索,有关自定义属性input操作
  2. shiro:入门程序(一)
  3. TT企业微信社群辅助,企业微信社群辅助工具,允许批量添加好友,自动同意添加请求,自动回复消息
  4. ajax 报0错误
  5. 日志分析工具ELK(二)
  6. Hexo博客插入图片的方法
  7. 浅析Java三大特性封装、继承、多态,及作业分析
  8. Linux 用户管理和提权
  9. js中的this指针的用法
  10. 《Microduino实战》——2.3 Microduino STM32核心系列