ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915
题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势。
首先这是个Nim博弈,必败局势是所有xor和为0.
那么自然变成了n个数里面取出一些数,使得xor和为0,求取法数。
首先由xor高斯消元得到一组向量基,但是这些向量基是无法表示0的。
所以要表示0,必须有若干0来表示,所以n-row就是消元结束后0的个数,那么2^(n-row)就是能组成0的种数。
对n==row特判一下。
代码:
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cstring>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <queue>
- #include <string>
- #define LL long long
- using namespace std;
- const int maxN = ;
- const int MOD = ;
- int n, s[maxN];
- void input()
- {
- scanf("%d", &n);
- for (int i = ; i < n; ++i)
- scanf("%d", &s[i]);
- }
- //xor高斯消元求线性基
- //时间复杂度O(30n)
- int xorGauss(int n)
- {
- int row = ;
- for (int i = ; i >= ; i--)
- {
- int j;
- for (j = row; j < n; j++)
- if(s[j]&(<<i))
- break;
- if (j != n)
- {
- swap(s[row], s[j]);
- for (j = ; j < n; j++)
- {
- if(j == row) continue;
- if(s[j]&(<<i))
- s[j] ^= s[row];
- }
- row++;
- }
- }
- return row;
- }
- void work()
- {
- int row, ans, k;
- row = xorGauss(n);
- ans = n-row;
- if (ans != -)
- {
- k = ;
- while (ans)
- {
- k <<= ;
- k %= MOD;
- ans--;
- }
- ans = k;
- }
- else
- ans = -;
- printf("%d\n", ans);
- }
- int main()
- {
- //freopen("test.in", "r", stdin);
- int T;
- scanf("%d", &T);
- for (int times = ; times < T; ++times)
- {
- input();
- work();
- }
- return ;
- }
ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)的更多相关文章
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- ACM学习历程—HDU 3949 XOR(xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...
- ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...
- ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...
- HDU 5833 Zhu and 772002 (高斯消元)
Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...
- 2016ACM/ICPC亚洲区沈阳站H - Guessing the Dice Roll HDU - 5955 ac自动机+概率dp+高斯消元
http://acm.hdu.edu.cn/showproblem.php?pid=5955 题意:给你长度为l的n组数,每个数1-6,每次扔色子,问你每个串第一次被匹配的概率是多少 题解:先建成ac ...
- HDU 3949 XOR 高斯消元
题目大意:给定一个数组,求这些数组通过异或能得到的数中的第k小是多少 首先高斯消元求出线性基,然后将k依照二进制拆分就可以 注意当高斯消元结束后若末尾有0则第1小是0 特判一下然后k-- 然后HDU输 ...
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- ACM学习历程—HDU 5534 Partial Tree(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题目大意是给了n个结点,让后让构成一个树,假设每个节点的度为r1, r2, ...rn,求f(x ...
随机推荐
- 使用 Xcode 5 生成和使用静态库
本文转载至 http://blog.csdn.net/qq331436155/article/details/18363267 静态库Static Libraryiosxcode 在项目中 ...
- 【BZOJ2466】[中山市选2009]树 树形DP
[BZOJ2466][中山市选2009]树 Description 图论中的树为一个无环的无向图.给定一棵树,每个节点有一盏指示灯和一个按钮.如果节点的按扭被按了,那么该节点的灯会从熄灭变为点亮(当按 ...
- An Ordinary Game(简单推导)
An Ordinary Game Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement There ...
- web.xml配置中的log4jRefreshInterval
采用spring框架的项目如何使用log4j在spring中使用log4j,有些方便的地方, 1.动态的改变记录级别和策略,即修改log4j.properties,不需要重启web应用,这需要在web ...
- java的小知识点
1 获取当前路径 System.getProperty("user.dir") System.getProperty()参数大全# java.version ...
- Moore-Penrose Matrix Inverse 摩尔-彭若斯广义逆 埃尔米特矩阵 Hermitian matrix
http://mathworld.wolfram.com/Moore-PenroseMatrixInverse.html 显然,埃尔米特矩阵主对角线上的元素都是实数的,其特征值也是实数.对于只包含实数 ...
- Linux c编程:线程属性
前面介绍了pthread_create函数,并且当时的例子中,传入的参数都是空指针,而不是指向pthread_attr_t结构的指针.可以使用pthread_attr_t结构修改线程默认属性,并把这些 ...
- lzugis—搭建属于自己的小型的版本号控制SVN
版权声明:本文为LZUGIS原创文章,未经同意不得转载. https://blog.csdn.net/GISShiXiSheng/article/details/28643575 对于不了解SVN的同 ...
- R语言图形base系统(一)
一般R作图有三大绘图系统:base系统.ggplot2绘图系统.lattice绘图系统. 本篇主要介绍base系统绘图时的图形参数.一般用plot()函数来完成.在R中,若 ...
- python 的for else语句
for中间不是break出来的,是正常循环完跳出循环的会执行else内的语句 while else语句也是如此 这个以前的常见语言没有,特此记录