题目链接: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高斯消元)的更多相关文章

  1. ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...

  2. ACM学习历程—HDU 3949 XOR(xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...

  3. ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...

  4. ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...

  5. HDU 5833 Zhu and 772002 (高斯消元)

    Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...

  6. 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 ...

  7. HDU 3949 XOR 高斯消元

    题目大意:给定一个数组,求这些数组通过异或能得到的数中的第k小是多少 首先高斯消元求出线性基,然后将k依照二进制拆分就可以 注意当高斯消元结束后若末尾有0则第1小是0 特判一下然后k-- 然后HDU输 ...

  8. ACM学习历程—HDU 5512 Pagodas(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...

  9. ACM学习历程—HDU 5534 Partial Tree(动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题目大意是给了n个结点,让后让构成一个树,假设每个节点的度为r1, r2, ...rn,求f(x ...

随机推荐

  1. c语言的编译和运行流程

    C语言源程序经过编译器进行词法分析 语法分析 等过程生成中间语言(object后缀的文件)编译期间会生成一个字符表和静态分配空间(如new static 全局变量)它们所需的内存空间可以计算出来放在链 ...

  2. SELinux状态修改

    查看SELinux状态: 1./usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态 SELinux status:         ...

  3. shell 字符串处理汇总(查找,替换等等)

    字符串: 简称“串”.有限字符的序列.数据元素为字符的线性表,是一种数据的逻辑结构.在计算机中可有不同的存储结构.在串上可进行求子串.插入字符.删除字符.置换字符等运算. 字符: 计算机程序设计及操作 ...

  4. Hibernate Criteria 查询使用

    转载 http://blog.csdn.net/woshisap/article/details/6747466 Hibernate 设计了 CriteriaSpecification 作为 Crit ...

  5. 红米4A手机刷开发版rom并且获取root权限

    1 bl解锁 Critical partition flashing is not allowed就是因为没有bl解锁. 注册小米账号并且关联手机. 下载bl解锁工具 http://www.miui. ...

  6. 【python】-- 类的反射

    反射 反射我们以后会经常用到,这个东西实现了动态的装配,通过字符串来反射类中的属性和方法 一.反射函数 1.hasarttr(obj,name_str) 作用:判断一个对象obj中是否有对应的name ...

  7. 【题解】Cutting Game

    [题解]Cutting Game vjudge 谈谈对\(sg\)函数的理解? 浅谈公平组合游戏IGC //@winlere #include<cstring> #include<c ...

  8. Android开发之深入理解泛型extends和super的区别

    摘要: 什么是泛型?什么是擦除边界?什么是上界限定或下界限定(子类型限定或超类型限定)?什么是类型安全?泛型extends关和super关键字结合通配符?使用的区别,两种泛型在实际Android开发中 ...

  9. Bootstrap学习1--响应式导航栏

    备注:最新Bootstrap手册:http://www.jqhtml.com/bootstraps-syntaxhigh/index.html <nav class="navbar n ...

  10. STM32 ~ 串口DMA通道查找

    STM32F4XX: /**************************************************************************************** ...