题意:有n堆石子,每个人只能从某一堆至少拿走一个,不能拿者败。问事先拿走某些堆的石子,使得先手必败。

析:将石子拆成二进制,未知数为1表示保留该堆石子,为0表示事先拿走该堆石子。最后求自由变元的数目,就是2的幂。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100 + 10;
const int mod = 1000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int equ, var, free_num;
bool a[maxn][maxn]; int Gauss(){
int max_r, col, k;
free_num = 0;
for(k = col = 0; k < equ && col < var; ++k, ++col){
max_r = k;
for(int i = k+1; i < equ; ++i)
if(a[i][col] > a[max_r][col]) max_r = i;
if(a[max_r][col] == 0){
--k;
++free_num; continue;
}
if(max_r != k){
for(int i = col; i <= var; ++i)
swap(a[k][i], a[max_r][i]);
}
for(int i = k+1; i < equ; ++i) if(a[i][col])
for(int j = col; j <= var; ++j)
a[i][j] ^= a[k][j];
}
return var - k;
} int main(){
int T; cin >> T;
while(T--){
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d", &m);
for(int j = 0; j < 31; ++j) a[j][i] = (m&(1<<j));
}
for(int i = 0; i < 31; ++i) a[i][n] = 0;
equ = 31; var = n;
int t = Gauss();
int ans = 1;
for(int i = 0; i < t; ++i)
ans = ans * 2 % mod;
printf("%d\n", ans);
}
return 0;
}

  

HDU 3915 Game (高斯消元)的更多相关文章

  1. HDU 3949 XOR 高斯消元

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

  2. hdu 5755(高斯消元——模线性方程组模板)

    PS. 看了大神的题解,发现确实可以用m个未知数的高斯消元做.因为确定了第一行的情况,之后所有行的情况都可以根据第一行推. 这样复杂度直接变成O(m*m*m) 知道了是高斯消元后,其实只要稍加处理,就 ...

  3. HDU 3949 XOR [高斯消元XOR 线性基]

    3949冰上走 题意: 给你 N个数,从中取出若干个进行异或运算 , 求最后所有可以得到的异或结果中的第k小值 N个数高斯消元求出线性基后,设秩为$r$,那么总共可以组成$2^r$中数字(本题不能不选 ...

  4. Time travel HDU - 4418(高斯消元)

    Agent K is one of the greatest agents in a secret organization called Men in Black. Once he needs to ...

  5. hdu 4870 rating(高斯消元求期望)

    Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  6. hdu 6465 线性变换高斯消元

    http://acm.hdu.edu.cn/showproblem.php?pid=6465 题意 给你三个点,再给你经过线性变换后的三个点,然后q次询问,给你一个点,需要你输出线性变换后的点 题解 ...

  7. HDU 3364 Lanterns 高斯消元

    Lanterns Problem Description   Alice has received a beautiful present from Bob. The present contains ...

  8. hdu 3915 高斯消元

    http://acm.hdu.edu.cn/showproblem.php?pid=3915 这道题目是和博弈论挂钩的高斯消元.本题涉及的博弈是nim博弈,结论是:当先手处于奇异局势时(几堆石子数相互 ...

  9. ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...

随机推荐

  1. 剑指offer——二叉树的深度与平衡二叉树的判断

    通过后续遍历,可以减少重复访问 #include <iostream> #include <string> using namespace std; struct Binary ...

  2. noVNC

    noNVC基础用法: 1.下载noVNC git clone https://github.com/novnc/noVNC.git 2.编辑qemu.conf配置文件 Vim /etc/libvirt ...

  3. C程序员必须知道的内存知识【英】

    C程序员必须知道的内存知识[英] 时间 2015-03-08 14:16:11  极客头条原文  http://marek.vavrusa.com/c/memory/2015/02/20/memory ...

  4. linux 磁盘管理与文件系统

    一.磁盘分区的意义 磁盘分区就是为了将磁盘分成不同的逻辑区域,每个分区可以有不同的文件系统 二. 磁盘分区是按照磁盘的柱面进行分区的,由于盘片在转动时的角速度都是一样的,所以磁头在最外层的磁道上读取信 ...

  5. 四分位数及matlab实现

    四分位数(quantile),解释及调用形式如下. quantile(x,y,z)的三个参数的说明如下:x表示要求的矩阵或者向量:y的取值为表示要求的分位数,如四分之一中位数0.25,四分之三中位数0 ...

  6. SpringMVC简单实例(看起来有用)

    SpringMVC简单实例(看起来有用) 参考: SpringMVC 基础教程 简单入门实例 - CSDN博客http://blog.csdn.net/swingpyzf/article/detail ...

  7. R基础之批处理--R IN ACTION

    1.5 批处理多数情况下,我们都会交互式地使用R:在提示符后输入命令,接着等待该命令的输出结果.偶尔,我们可能想要以一种重复的.标准化的.无人值守的方式执行某个R程序,例如,你可能需要每个月生成一次相 ...

  8. linux-常用指令1

    掌握下面的命令是最基本的噢!那是我们使用一个系统最基本的操作. 玩过dos么,其实,linux下的文件操作和dos差不多.没什么难的,多练习就记住了.下面如果有条件的话请跟我一样操作吧!百看不如一做. ...

  9. Mysql总结_03_mysql常用命令

    一.MySQL服务的启动和停止 net stop mysql net start mysql 二.登陆mysql mysql -u用户名 -p用户密码 键入命令mysql -uroot -p, 回车后 ...

  10. HDU5446 Unknown Treasure(组合数膜合数-->Lucas+中国剩余定理)

    >On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown ...