题意:有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. c#学习内容

    学习winform+DevExpress 界面制作 wpf UIAutomation 控制别的程序 ok c#通过句柄控制别的程序  ok c# 截图  ok c# 多线程  ok c# 数据库myq ...

  2. Spring中如何动态注入Bean实例教程

    前言 在Spring中提供了非常多的方式注入实例,但是由于在初始化顺序的不同,基于标注的注入方式,容易出现未被正确注入成功的情况. 本文将介绍一种在实际项目中基于动态的方式来提取Spring管理的Be ...

  3. LINQ 学习路程 -- 查询操作 Expression Tree

    表达式树就像是树形的数据结构,表达式树中的每一个节点都是表达式, 表达式树可以表示一个数学公式如:x<y.x.<.y都是一个表达式,并构成树形的数据结构 表达式树使lambda表达式的结构 ...

  4. 算法(Algorithms)第4版 练习 2.3.25

      代码实现: public static void sort(Comparable[] a) { StdRandom.shuffle(a);//eliminate dependence on inp ...

  5. Qt之界面实现技巧-- 窗体显示,绘制背景,圆角,QSS样式

    转自 --> http://blog.sina.com.cn/s/blog_a6fb6cc90101dech.html 总结一下,在开发Qt的过程中的一些技巧!可遇而不可求... 一.主界面 1 ...

  6. Windows- 改变cmd控制台默认显示编码

    在中国的电脑会要求兼容gbk编码,所以微软进入中国市场也顺应中国的要求,其中最明显的就是在cmd上默认的显示就是GBK .当开发人员在运行一些有打印中文的程序时,由于编码采用国际兼容版本的utf_8等 ...

  7. HIVE- 数据倾斜

    数据倾斜就是由于数据分布不均匀,数据大量集中到一点上,造成数据热点.大多数情况下,分为一下三种情况: 1.map端执行比较快,reduce执行很慢,因为partition造成的数据倾斜. 2.某些re ...

  8. Codeforces 448C Painting Fence:分治

    题目链接:http://codeforces.com/problemset/problem/448/C 题意: 有n个木板竖着插成一排栅栏,第i块木板高度为a[i]. 你现在要将栅栏上所有地方刷上油漆 ...

  9. Codeforces 509F Progress Monitoring:区间dp【根据遍历顺序求树的方案数】

    题目链接:http://codeforces.com/problemset/problem/509/F 题意: 告诉你遍历一棵树的方法,以及遍历节点的顺序a[i],长度为n. 问你这棵树有多少种可能的 ...

  10. Linux-NoSQL之Redis(一)

    1.Redis介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(s ...