题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275

题意:给你n个数,可以选择任意个数异或,但是要使得最后的异或值最大。

我们把每个数用二进制表示,要使得最后的异或值最大,就是要让高位尽量为1,高位能不能为1就必须用高斯消元判断了。

1. 根据数的二进制表示,建立方程组的矩阵,结果那列置为1。
2. 从下往上高斯消元(高位放下面),如果该行有未被控制的变元,则该行的结果一定为1,且该变元控制该行。
3. 从该行往上依次消掉(异或)该变元。
4. 如果该行没有可以用来控制的变元,如果最后一列是0,则该行结果也为1,否则该行结果为0。这里能抱着已用来控制的变元的系数全是0,因为在第3步时就消掉该行以上此列的0了,后面0与0以后还是0。所以如果最后一列是0, 即该行方程也可以成立,故结果为1。

建立方程:

a11x1+a21x2……=d[1]

a12x1+a22x2……=d[2]

……

很好的题目、

 /* ***********************************************
Author :kuangbin
Created Time :2014-1-31 0:48:47
File Name :E:\2014ACM\SGU\SGU275.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; long long bit[];
int a[][];
bool used[]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
bit[] = ;
for(int i = ;i < ;i++)
bit[i] = *bit[i-];
int n;
long long x;
while(scanf("%d",&n) == )
{
for(int i = ;i < n;i++)
{
cin>>x;
for(int j = ;j < ;j++)
{
if(x & bit[-j])
a[j][i] = ;
else a[j][i] = ;
}
}
for(int i = ;i < ;i++)
a[i][n] = ;
memset(used,false,sizeof(used));
long long ans = ;
for(int i = ;i < ;i++)
{
int x = -;
for(int j = ;j < n;j++)
if(a[i][j] && !used[j])
{
x = j;
break;
}
if(x == - && a[i][n] == )
ans += bit[-i];
else if(x != -)
{
ans += bit[-i];
for(int k = i+; k < ;k++)
if(a[k][x])
{
for(int j = ;j <= n;j++)
a[k][j] ^= a[i][j];
}
}
}
cout<<ans<<endl;
}
return ;
}

SGU 275. To xor or not to xor (高斯消元法)的更多相关文章

  1. 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 ...

  2. ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...

  3. SGU 275 To xor or not to xor

    time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard output: standard The ...

  4. SGU 275 To xor or not to xor (高斯消元)

    题目链接 题意:有n个数,范围是[0, 10^18],n最大为100,找出若干个数使它们异或的值最大并输出这个最大值. 分析: 一道高斯消元的好题/ 我们把每个数用二进制表示,要使得最后的异或值最大, ...

  5. SGU 275 To xor or not to xor(高斯消元)

    题意: 从n个数中选若干个数,使它们的异或和最大.n<=100 Solution 经典的异或高斯消元. //O(60*n) #include <iostream> using nam ...

  6. sgu 275 To xor or not to xor 线性基 最大异或和

    题目链接 题意 给定\(n\)个数,取其中的一个子集,使得异或和最大,求该最大的异或和. 思路 先求得线性基. 则求原\(n\)个数的所有子集的最大异或和便可转化成求其线性基的子集的最大异或和. 因为 ...

  7. SGU 275 To xor or not to xor【最大xor和 高斯消元】

    题目大意:给你n个数(n<=100)要你找出若干个数使他们的异或和最大 思路:高斯-若当消元消完以后削成若干个独立的行向量,将它们异或起来就好 #include<cstdio> #i ...

  8. sgu To xor or not to xor

    题意:从n个数中,选择一些数,使得异或最大. #include <cstdio> #include <cstring> #include <algorithm> # ...

  9. BZOJ 2115: [Wc2011] Xor [高斯消元XOR 线性基 图]

    啦啦啦 题意: N 个点M条边的边带权的无向图,求1到n一条XOR和最大的路径 感觉把学的东西都用上了.... 1到n的所有路径可以由一条1到n的简单路径异或上任意个简单环得到 证明: 如果环与路径有 ...

随机推荐

  1. JQuery对CheckBox的一些相关操作

    一.通过选择器选取CheckBox: 1.给CheckBox设置一个id属性,通过id选择器选取: <input type="checkbox" name="myB ...

  2. B - C Looooops POJ - 2115 (扩展欧几里得)

    题目链接:https://cn.vjudge.net/contest/276376#problem/B 题目大意:for( int  i= A ; i != B; i+ = c ),然后给你A,B,C ...

  3. bellman-ford算法(判断有没有负环)

    #include <iostream> #include <vector> #include<string> #include<cstring> usi ...

  4. linux 串口驱动(三) 【转】

    转自:http://blog.chinaunix.net/uid-27717694-id-3495825.html 三.串口的打开在用户空间执行open操作的时候,就会执行uart_ops->o ...

  5. MVC Autofac依赖注入

    通过Dll实现全部类的属性注入,该演示实例主要通过多层架构中单一的对象方式来演示,没有采取接口的方式, 新建AutoFacHelper类,如下代码: public class AutoFacHelpe ...

  6. Python api认证

    本节内容: 基本的api 升级的api 终极版api 环境:Djanao, 项目名:api_auto, app:api 角色:api端,客户端,黑客端 1.基本的api [api端] #api_aut ...

  7. CF1064A 【Make a triangle!】

    要让这个三角形合法,只需满足三角形不等式 即$a+b>c$,设$c=max\left\{a,b,c\right\}$,上式转化为$c<a+b$ 如果已经满足,不需消耗代价 否则消耗$c-a ...

  8. linux上jdk管理

    查看CentOS自带JDK是否已安装. yum list installed |grep java. 若有自带安装的JDK,卸载CentOS系统自带Java环境? yum -y remove java ...

  9. Qt编程之悲惨世界

    最近需要给人写点基于QtWebkit的代码,算是领教了Qt编程的痛苦之处. QNetworkConfigurationManager::isOnline() 只有在编译平台上能运行,拷贝到其他Wind ...

  10. hdu 1754 线段树(单点替换 区间最值)

    Sample Input5 61 2 3 4 5Q 1 5 //1-5结点的最大值U 3 6 //将点3的数值换成6Q 3 4Q 4 5U 2 9Q 1 5 Sample Output5659 # i ...