hdu 5088 高斯消元n堆石子取k堆石子使剩余异或值为0
http://acm.hdu.edu.cn/showproblem.php?pid=5088
求能否去掉几堆石子使得nim游戏胜利
我们可以把题目转化成求n堆石子中的k堆石子数异或为0的情况数。使用x1---xn表示最终第i堆石子到底取不取(1取,0不取),将每堆石子数画成2进制的形式,列成31个方程来求自由变元数,最后由于自由变元能取1、0两种状态,所以自由变元数多于0即可输出Yes。
注意有40+个方程,因为A[I]<=1e12....
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define clr1(x) memset(x,-1,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
typedef unsigned long long ULL;
const int modo = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int inf = 0x3fffffff;
const LL _inf = 1e18;
const int maxn = 1005,maxm = 10005; #define MAXN 1100
#define MOD 1000007
#define weishu 42
LL a[MAXN], g[MAXN][MAXN];
int Gauss(int n) {
int i, j, r, c, cnt;
for (c = cnt = 0; c < n; c++) {
for (r = cnt; r < weishu; r++) {
if (g[r][c])
break;
}
if (r < weishu) {
if (r != cnt) {
for (i = 0; i < n; i++)
swap(g[r][i], g[cnt][i]);
}
for (i = cnt + 1; i < weishu; i++) {
if (g[i][c]) {
for (j = 0; j < n; j++)
g[i][j] ^= g[cnt][j];
}
}
cnt++;
}
}
return n - cnt;
}
int main() {
int c;
int n, i, j;
int ans, vary;
scanf("%d", &c);
while (c--) {
int fuck = 0;
scanf("%d", &n);
for (i = 0; i < n; i++){
scanf("%I64d", &a[i]);
fuck ^= a[i];
}
for (i = 0; i < weishu; i++) {
for (j = 0; j < n; j++)
g[i][j] = (a[j] >> i) & 1;
}
vary = Gauss(n);
//printf("%d\n", vary);
if(vary <= 0 )//|| (fuck == 0 && vary <= 1))
puts("No");
else
puts("Yes"); }
return 0;
}
hdu 5088 高斯消元n堆石子取k堆石子使剩余异或值为0的更多相关文章
- HDU 2827 高斯消元
模板的高斯消元.... /** @Date : 2017-09-26 18:05:03 * @FileName: HDU 2827 高斯消元.cpp * @Platform: Windows * @A ...
- hdu 3915 高斯消元
http://acm.hdu.edu.cn/showproblem.php?pid=3915 这道题目是和博弈论挂钩的高斯消元.本题涉及的博弈是nim博弈,结论是:当先手处于奇异局势时(几堆石子数相互 ...
- HDU 3359 高斯消元模板题,
http://acm.hdu.edu.cn/showproblem.php?pid=3359 题目的意思是,由矩阵A生成矩阵B的方法是: 以a[i][j]为中心的,哈曼顿距离不大于dis的数字的总和 ...
- [置顶] hdu 4418 高斯消元解方程求期望
题意: 一个人在一条线段来回走(遇到线段端点就转变方向),现在他从起点出发,并有一个初始方向, 每次都可以走1, 2, 3 ..... m步,都有对应着一个概率.问你他走到终点的概率 思路: 方向问 ...
- HDU 4418 高斯消元解决概率期望
题目大意: 一个人在n长的路径上走到底再往回,走i步停下来的概率为Pi , 求从起点开始到自己所希望的终点所走步数的数学期望 因为每个位置都跟后m个位置的数学期望有关 E[i] = sigma((E[ ...
- 高斯消元 o(n^3) 取摸和不取摸
#include<bits/stdc++.h> using namespace std; ; int a[MAXN][MAXN];//增广矩阵 int x[MAXN];//解集 bool ...
- HDU 3364 高斯消元
Lanterns Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- hdu 2262 高斯消元求期望
Where is the canteen Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- hdu 4418 高斯消元求期望
Time travel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- L1-006 连续因子(20)(思路+测试点分析)
L1-006 连续因子(20 分) 一个正整数 N 的因子中可能存在若干连续的数字.例如 630 可以分解为 3×5×6×7,其中 5.6.7 就是 3 个连续的数字.给定任一正整数 N,要求编写程序 ...
- 基因组表达分析:如何选择RNA-seq vs. 芯片
基因组表达分析:如何选择RNA-seq vs. 芯片 发布日期:2017-03-29 10:00 DNA 芯片(上图左侧)由附着在表面的核酸探针组成.首先,从样品中提取 RNA 并转化为互补 DNA( ...
- Tinyos学习笔记(三)
读取Telosb内部传感器数据,并在计算机上显示. senseC.nc代码如下: #include "Timer.h" #include "sense.h" # ...
- Python pip下载安装库 临时用清华镜像命令
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple C:\Users\mu\pip 新建pip.ini [global] index-url ...
- mysql5.6改进子查询实测试
表t1,t2 各自生成100万条记录. 表引擎 myiasm ,查询语句 select * from t1 where id2 in (select id2 from t2 ) 查询速度 2.x秒 ...
- swift 要点
swift 基本语法注意点 通常来说,编程语言教程中的第一个程序应该在屏幕上打印“Hello, world”.在 Swift 中,可以用一行代码实现 print("Hello, world! ...
- dbc file
DBC文件是用来描述CAN网络通信信号的一种格式文件.它可以用来监测与分析CAN网络上的报文数据,也可以用来模拟某个CAN节点.(DBC file is a format file used to d ...
- 基于centos6.5 hadoop 集群搭建
1.修改Linux主机名2.修改IP3.修改主机名和IP的映射关系 ######注意######如果你们公司是租用的服务器或是使用的云主机(如华为用主机.阿里云主机等) /etc/hosts里面要配置 ...
- Redis学习笔记:windows上redis的安装运行
Redis的windows版本地址https://github.com/MicrosoftArchive/redis 下载之后解压之 在当前解压目录下可以看到如下文件 在当前目录下打开命令行窗口,输入 ...
- ''TclError: no display name and no $DISPLAY environment variable''解决方法
在模块前写入一下代码: import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt 具体解释见 http://m ...