SGU 275. To xor or not to xor(高斯消元)
2014-07-30 18:23
246 查看
题目大意:给你n个数字,让你从n个数中,选择一些数,使得异或最大。
如果想使异或的值更大一些,那么就保证高位尽量为1,这样先让最后一列的结果等于1,然后解方程。当到达第i行时,通过第0~i-1行对第i行经行求解,如果有解就要把这一位的结果加上。
这里用低位表示的高位。
memory limit per test: 65536 KB
input: standard
output: standard
The sequence of non-negative integers A1, A2, ..., AN is given. You are to find some subsequence Ai1, Ai2, ..., Aik (1 <= i1 < i2 < ... < ik <= N) such, that Ai1 XOR Ai2 XOR
... XOR Aik has a maximum value.
Input
The first line of the input file contains the integer number N (1 <= N <= 100). The second line contains the sequence A1, A2, ..., AN (0 <= Ai <= 10^18).
Output
Write to the output file a single integer number -- the maximum possible value of Ai1 XOR Ai2 XOR ... XOR Aik.
Sample test(s)
Input
3 11 9 5
Output
14
如果想使异或的值更大一些,那么就保证高位尽量为1,这样先让最后一列的结果等于1,然后解方程。当到达第i行时,通过第0~i-1行对第i行经行求解,如果有解就要把这一位的结果加上。
这里用低位表示的高位。
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 sequence of non-negative integers A1, A2, ..., AN is given. You are to find some subsequence Ai1, Ai2, ..., Aik (1 <= i1 < i2 < ... < ik <= N) such, that Ai1 XOR Ai2 XOR
... XOR Aik has a maximum value.
Input
The first line of the input file contains the integer number N (1 <= N <= 100). The second line contains the sequence A1, A2, ..., AN (0 <= Ai <= 10^18).
Output
Write to the output file a single integer number -- the maximum possible value of Ai1 XOR Ai2 XOR ... XOR Aik.
Sample test(s)
Input
3 11 9 5
Output
14
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #define eps 1e-10 ///#define M 1000100 #define LL __int64 ///#define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 210; using namespace std; int a[maxn][maxn]; int n; void Gauss() { LL ans = 0; int i, j; for(int k = 0; k < 61; k++) { a[k] = 1; for(i = 0; i < k; i++) { for(j = 0; j < n; j++) if(a[i][j]) break; if(j < n && a[k][j]) for(; j <= n; j++) a[k][j] ^= a[i][j]; } for(i = 0; i < n; i++) if(a[k][i]) break; if(i < n || (i == n && !a[k] )) ans += (1LL<<(60-k)); } cout<<ans<<endl; } int main() { while(cin >>n) { memset(a, 0, sizeof(a)); LL x; for(int i = 0; i < n; i++) { cin >>x; for(int j = 60; j >= 0; j--) if((1LL<<j)&x)a[60-j][i] = 1; } Gauss(); } return 0; }
相关文章推荐
- SGU 200. Cracking RSA(高斯消元+高精度)
- SGU 200 Cracking RSA (高斯消元+大数高精度)
- SGU 200. Cracking RSA(高斯消元+高精度)
- sgu200--Cracking RSA(高斯消元问题6,求乘积为完全平方数的种数)
- SGU 275 To xor or not to xor 高斯消元求N个数中选择任意数XORmax
- SGU - 200 Cracking RSA 高斯消元
- sgu260:Puzzle(高斯消元)
- SGU 200 Cracking RSA (高斯消元)
- SGU 200 Cracking RSA (高斯消元)
- SGU 275 To xor or not to xor(高斯消元)
- SGU 260.Puzzle (异或高斯消元)
- SGU 275 To xor or not to xor (贪心+高斯消元)
- ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)
- sgu200:Cracking RSA(模意义下高斯消元求自由变元个数)
- SGU 200. Cracking RSA 高斯消元
- SGU 275 To xor or not to xor【最大xor和 高斯消元】
- SGU 200 Cracking RSA (高斯消元)
- SGU 200.Cracking RSA(高斯消元)
- sgu-200 Cracking RSA(简单的高斯消元求自由变元个数)
- SGU 200 Cracking RSA (高斯消元)