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 ...
随机推荐
- suricata 原文记录
如何在 Linux 系统上安装 Suricata 入侵检测系统 编译自:http://xmodulo.com/install-suricata-intrusion-detection-system-l ...
- appache压力测试
apache自带压力工具测试说明: Usage: ab [options] [http[s]://]hostname[:port]/pathOptions are: -n requests Numbe ...
- IOS初级:app的图标
1,首先准备6张png图,分辨率一定要正确,不然报错(The app icon set named "AppIcon" did not have any applicable co ...
- regexper-正则表达式检验
https://regexper.com 例如:输入 \s.?\w{1,3}(\d(\W)(#?\d{1..4}))
- mysql中的handler_read_%
mysql> show status like 'handler_read_%'; +-----------------------+-------+ | Variable_name | Val ...
- 进度条的制作unity
不说了直接上代码: LoadingPanel: using UnityEngine;using System.Collections;using UnityEngine.UI;using UnityE ...
- rails 新建user的phonenumber字段
1.新建字段 //rails g migration add_字段名_to_表名 字段名:字段类型 rails g migration add_title_to_contents title:stri ...
- PL/SQL Developer 导出csv文件,用excel打开中文显示乱码
用PL/SQL Developer的导出csv功能把sql语句的查询结果导出到一个csv文件.这个sql查询的结果里面有中文,最后用execel打开的时候发现中文全部是乱码. 方法 1 导出csv ...
- presentation skills
下面是从一个网站摘录下来的关于presentation skill需要回答的14个问题:网站的地址为:http://www.mindtools.com/pages/article/newCS_96.h ...
- windows下Oracle数据库完全删除
1.1 停止所有oracle的服务 1.2 删除安装路径 app及其下所有文件 1.3 删除注册表 regedit 进入 在下列列表中找到与oracle相关的注册表项删除 1.HKEY_L ...