SGU 275 To xor or not to xor
memory limit per test: 65536 KB
output: standard
11 9 5
分析
Implementation
#include <bits/stdc++.h>
using namespace std;
int a[][];
#define LL long long
LL b[];
LL res;
//写好每一个循环
//写好每一个if else
void gauss(int n, int m){
for(int i=m-; i>=; i--){
int flag=;
for(int j=; j<n; j++)
if(a[i][j]){
flag=;
for(int k=i-; k>=; k--)
if(a[k][j])
for(int l=; l<=n; l++)
a[k][l]^=a[i][l];
break;
}
if(!flag||flag&&!a[i][n]) res+=1LL<<i;
}
} int main(){
int n;
cin>>n;
for(int i=; i<n; i++)
cin>>b[i];
for(int i=; i<; i++){
for(int j=; j<n; j++){
a[i][j]=(bool)(b[j]&1LL<<i);
}
a[i][n]=;
}
gauss(n, );
cout<<res<<endl;
}
P.S. 看到一份比较短的代码,思路也是高斯消元,学习一个。
#include <iostream>
using namespace std;
int n;
long long ans, b, a[];
int main(){
int n;
cin>>n;
for(int i=; i<n; i++) cin>>a[i];
for(int i=; i>=; i--)
for(int j=; j<n; j++) if(a[j]>>i&){
b=a[j];
if(!(ans>>i&)) ans^=b;
for(int k=; k<n; k++) if(a[k]>>i&) a[k]^=b;
}
cout<<ans<<endl;
}
SGU 275 To xor or not to xor的更多相关文章
- SGU 275 To xor or not to xor 高斯消元求N个数中选择任意数XORmax
275. To xor or not to xor The sequence of non-negative integers A1, A2, ..., AN is given. You are ...
- ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...
- SGU 275. To xor or not to xor (高斯消元法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 题意:给你n个数,可以选择任意个数异或,但是要使得最后的异或值最大. 我们把每 ...
- SGU 275 To xor or not to xor (高斯消元)
题目链接 题意:有n个数,范围是[0, 10^18],n最大为100,找出若干个数使它们异或的值最大并输出这个最大值. 分析: 一道高斯消元的好题/ 我们把每个数用二进制表示,要使得最后的异或值最大, ...
- SGU 275 To xor or not to xor(高斯消元)
题意: 从n个数中选若干个数,使它们的异或和最大.n<=100 Solution 经典的异或高斯消元. //O(60*n) #include <iostream> using nam ...
- sgu 275 To xor or not to xor 线性基 最大异或和
题目链接 题意 给定\(n\)个数,取其中的一个子集,使得异或和最大,求该最大的异或和. 思路 先求得线性基. 则求原\(n\)个数的所有子集的最大异或和便可转化成求其线性基的子集的最大异或和. 因为 ...
- SGU 275 To xor or not to xor【最大xor和 高斯消元】
题目大意:给你n个数(n<=100)要你找出若干个数使他们的异或和最大 思路:高斯-若当消元消完以后削成若干个独立的行向量,将它们异或起来就好 #include<cstdio> #i ...
- sgu To xor or not to xor
题意:从n个数中,选择一些数,使得异或最大. #include <cstdio> #include <cstring> #include <algorithm> # ...
- BZOJ 2115: [Wc2011] Xor [高斯消元XOR 线性基 图]
啦啦啦 题意: N 个点M条边的边带权的无向图,求1到n一条XOR和最大的路径 感觉把学的东西都用上了.... 1到n的所有路径可以由一条1到n的简单路径异或上任意个简单环得到 证明: 如果环与路径有 ...
随机推荐
- [转] 值得推荐的C/C++框架和库
http://www.cppblog.com/merlinfang/archive/2014/12/26/209311.aspx
- 使用CuteSlider做网站炫酷的幻灯片
cuteSlider 1.预览 官网:http://www.cuteslider.com/ 应用:http://www.dutphonelab.org/ 2.资料 文档:http://pan.baid ...
- System.Net.Sockets.Socket SendAsync System.ObjectDisposedException: Cannot access a disposed object.
发生未处理的域异常! System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net ...
- 全面理解HTTP
URL与URI 我们经常接触到的就是URL了,它就是我们访问web的一个字符串地址,那么URI是什么呢?他们是什么关系呢? URL:uniform resource location 统一资源定位符U ...
- 【夯实Mysql基础】MySQL在Linux系统下配置文件及日志详解
本文地址 分享提纲: 1. 概述 2. 详解配置文件 3. 详解日志 1.概述 MySQL配置文件在Windows下叫my.ini,在MySQL的安装根目录下:在Linux下叫my.cnf,该文件位于 ...
- C++ Set & MultiSet
转自http://www.cppblog.com/wanghaiguang/archive/2012/06/05/177627.html STL Set介绍集合(Set)是一种包含已排序对象的关联容器 ...
- SilverLight自定义ImageButton
SilverLight中XAML的写法和WPF一样,但是发现在自定义按钮上,没有WPF来的容易,下面说说我制作SilverLight中的ImageButton的一些思路. 在SilverLight中, ...
- Ubuntu下类似于Total Commander的两个工具
Total Commander for linux Is there a Linux version? Unfortunately not. Because of problems with port ...
- 学习笔记——Maven实战(四)基于Maven的持续集成实践
Martin的<持续集成> 相信很多读者和我一样,最早接触到持续集成的概念是来自Martin的著名文章<持续集成>,该文最早发布于2000年9月,之后在2006年进行了一次修订 ...
- 【MyEclipse 2015】 逆向破解实录系列【终】(纯研究)
声明 My Eclipse 2015 程序版权为Genuitec, L.L.C所有. My Eclipse 2015 的注册码.激活码等授权为Genuitec, L.L.C及其付费用户所有. 本文只从 ...