SPOJ XMAX - XOR Maximization
XMAX - XOR Maximization
Given a set of integers S = { a1, a2, a3, ... a|S| }, we define a function X on S as follows:
X( S ) = a1 ^ a2 ^ a3 ^ ... ^ a|S|.
(^ stands for bitwise 'XOR' or 'exclusive or')
Given a set of N integers, compute the maximum of the X-function over all the subsets of the given starting set.
Input
The first line of input contains a single integer N, 1 <= N <= 105.
Each of the next N lines contain an integer ai, 1 <= ai <= 1018.
Output
To the first line of output print the solution.
Example
Input: 3
1
2
4
Output: 7
高斯消元类似。尽量变幻成上三角矩阵。每一位尽量留一个1
如矩阵:
010000
001000
000100
000010
就是一个理想的矩阵。
/* ***********************************************
Author :guanjun
Created Time :2016/9/8 15:30:01
File Name :spoj_XMAX.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(ll a,ll b){
return a>b;
}
ll a[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
for(int i=;i<=n;i++)cin>>a[i];
sort(a+,a++n,cmp);
int row=;
for(int i=;i>=;i--){
for(int j=row;j<=n;j++){
if(a[j]&(1LL<<i)){
swap(a[row],a[j]);
for(int k=;k<=n;k++){
if((a[k]&(1LL<<i))&&(k!=row)){
a[k]=a[k]^a[row];
}
//puts("YES");
}
row++;
}
}
}
ll ans=0LL;
for(int i=;i<=n;i++){
// cout<<a[i]<<endl;
ans^=a[i];
}
cout<<ans<<endl;
}
return ;
}
SPOJ XMAX - XOR Maximization的更多相关文章
- SPOJ Find the max XOR value(二进制,贪心即可)
You have two integers L and R, and you are required to find the max xor value of a and b where L < ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ COT3 Combat on a tree(Trie树、线段树的合并)
题目链接:http://www.spoj.com/problems/COT3/ Alice and Bob are playing a game on a tree of n nodes.Each n ...
- BZOJ 2588: Spoj 10628. Count on a tree 树上跑主席树
2588: Spoj 10628. Count on a tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/J ...
- Bzoj 2588: Spoj 10628. Count on a tree 主席树,离散化,可持久,倍增LCA
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2588 2588: Spoj 10628. Count on a tree Time Limit ...
- 图论(网络流):SPOJ OPTM - Optimal Marks
OPTM - Optimal Marks You are given an undirected graph G(V, E). Each vertex has a mark which is an i ...
- BZOJ 2588: Spoj 10628. Count on a tree( LCA + 主席树 )
Orz..跑得还挺快的#10 自从会树链剖分后LCA就没写过倍增了... 这道题用可持久化线段树..点x的线段树表示ROOT到x的这条路径上的权值线段树 ----------------------- ...
- 【BZOJ2588】Spoj 10628. Count on a tree 主席树+LCA
[BZOJ2588]Spoj 10628. Count on a tree Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lasta ...
- SPOJ SUBXOR
SPOJ SUBXOR 题意 给定一个由正整数构成的数组, 求 异或和小于k 的子序列的个数. 题解 假设答案区间为 [L, R], XOR[L, R] 等价于 XOR[1, L - 1] ^ XOR ...
随机推荐
- zabbix3.0_网络发现问题
问题1. Zabbix网络发现system.uanem找不到主机,打开zabbix_server.conf文件的debug DebugLevel=5 # 错误信息如下 # item [system.u ...
- JavaScipt30(第一个案例)(主要知识点:键盘事件以及transitionend)
今天得到一个github练习项目,是30个原生js写成的小例子,麻雀虽小五脏俱全,现在记录一下第一个. 第一个是键盘按键时页面上对应的键高亮,同时播放音频,松开后不再高亮. 我自己实现了一下,然后查看 ...
- CodeFrist基础_Fluent Api
一丶首先新建两个实体类 public class Student { public int StudentKey { get; set; } public string StudentName { g ...
- 软件工程师需要了解的网络知识:从铜线到HTTP(一)—— 前言
转自:https://lvwenhan.com/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/485.html?hmsr=toutiao.io&utm_medium ...
- linux性能优化cpu-02平均负载
每次我们系统变慢时,我们通常做的第一件事就是top命令或者uptime命令,看一下系统的负载情况,比如下面: 我在命令行中输入uptime 22:15:51 表示当前系统时间 up 13 min ...
- docker-ce安装官翻
参考http://www.cnblogs.com/maple42/p/5868846.htmlhttp://blog.csdn.net/lizehua123/article/details/50601 ...
- linux命令 info
info命令是Linux下info格式的帮助指令. 就内容来说,info页面比man page编写得要更好.更容易理解,也更友好,但man page使用起来确实要更容易得多.一个man page只有一 ...
- Jmeter BeanShell PreProcessor使用笔记
打印log log.info("content:" + content); 将字符串转化为JsonString import com.alibaba.fastjson.JSON; ...
- 关于JavaScript的一些笔试题
1.原题: function Foo() { getName = function () { alert (); }; return this; } Foo.getName = function () ...
- Java 字符串总结
三种字符串类:String,StringBuilder,StringBuffer String类 1. 常用构造器 构造器 public String(char value[]) public ...