【高斯消元】[SGU275]To xor or not to xor
来源:互联网 发布:监控干扰器软件 编辑:程序博客网 时间:2024/06/02 11:09
题目大意
就是给你n个数然后从中选择一些出来异或求异或可得到的最大值
题目分析
根据题目我们可以发现假设我们的答案是
代码
离线算法
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int MAXN = 100;long long A[MAXN+10];long long Bits[MAXN+10];long long T[MAXN+10][MAXN+10], Ma[MAXN+10][MAXN+10];bool C[MAXN+10], vis[MAXN+10];int x[MAXN+10];bool check(int n, int m, int k){ int row, col; memset(x, 0, sizeof x); memset(vis, 0, sizeof vis); for(row = col = 1;row<=k&&col<=n;row++, col++){ if(!Ma[row][col]) for(int j=row+1;j<=k;j++){ if(Ma[j][col]){ swap(Ma[j], Ma[row]); break; } } if(!Ma[row][col]){ row--; continue; } for(int i=row+1;i<=k;i++){ if(Ma[i][col]){ for(int j=col;j<=m;j++) Ma[i][j] ^= Ma[row][j]; } } } //row--; for(int i=row;i<=k;i++) if(Ma[i][m]) return false; return true;}int main(){ int n; scanf("%d", &n); for(int i=1;i<=n;i++) scanf("%I64d", &A[i]); Bits[1] = 1; memset(T, 0, sizeof T); for(int i=2;i<=60;i++) Bits[i] = Bits[i-1] << 1; for(int i=60;i>=1;i--){ T[i][n+1] = 1; for(int j=1;j<=n;j++) if((Bits[i] & A[j]) > 0) T[i][j] = 1; memcpy(Ma, T, sizeof Ma); if(!check(n, n+1, 60)) T[i][n+1] = 0; } long long ans = 0; for(int i=1;i<=60;i++) ans += 1LL * T[i][n+1] * Bits[i]; printf("%I64d\n", ans); return 0;}/*311 9 51011 = 111001 = 9101 = 51 1 1 10 1 1 00 0 1 10 0 0 1*/
在线算法
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 100;long long A[MAXN+10], Bits[MAXN+10], Ma[MAXN+10][MAXN+10], C[MAXN+10], T[MAXN+10], ans, n;bool solve(int n, int m, int k){ for(int i=1;i<=m;i++) if(Ma[n][i]){ if(C[i]){ for(int j=i;j<=k;j++) Ma[n][j] ^= Ma[C[i]][j]; }else{ C[i] = n; return true; } } return Ma[n][k] == 0;}int main(){ scanf("%I64d", &n); for(int i=1;i<=n;i++) scanf("%I64d", &A[i]); Bits[1] = 1; for(int i=2;i<=60;i++) Bits[i] = Bits[i-1] << 1; for(int i=60;i>=1;i--){ memset(T, 0, sizeof T); for(int j=1;j<=n;j++){ if((A[j] & Bits[i]) > 0) T[j] = 1; } memcpy(Ma[i], T, sizeof Ma[i]); Ma[i][n+1] = 1; if(solve(i, n, n+1)) ans += Bits[i]; } printf("%I64d\n", ans); return 0;}
0 0
- sgu275 To xor or not to xor ----高斯消元复习
- [SGU275]To xor or not to xor 枚举+高斯消元
- 高斯消元 SGU275 To xor or not to xor
- 【高斯消元】[SGU275]To xor or not to xor
- 【高斯消元】[SGU275]To xor or not to xor
- sgu275--To xor or not to xor(高斯消元问题5,子序列异或的最大和)
- sgu275:To xor or not to xor(最大异或和)
- To xor or not to xor SGU
- SGU275. To xor or not to xor(高斯消元求N个数中任取M个数求得异或最大值)
- SGU 275. To xor or not to xor(高斯消元)
- SGU 275 To xor or not to xor (高斯消元)
- SGU 275 To xor or not to xor (高斯消元)
- SGU_275 To xor or not to xor gauss
- SGU 275 To xor or not to xor
- 【SGU 275】 To xor or not to xor
- To xor or not to xor 高斯消元求异或
- sgu 275 To xor or not to xor(高斯消元判断是否有解)
- SGU 275 To xor or not to xor (贪心+高斯消元)
- Hdu 2024C语言合法标识符
- 设计模式——工厂方法模式
- Redis 源码分析 (一)Redis竟然用 C 语言进行面向对象编程
- Android Tip : Android 获取当前Activity对象的方式:
- 身份证号码编码方法及校验算法
- 【高斯消元】[SGU275]To xor or not to xor
- ubuntu需要额外安装的包用于支持android sdk的运行
- Git使用教程
- PHP文件上传
- [Node入门] => 读书笔记(二)
- HDOJ 5615 Jam's math problem
- Java将json数据导入到excel
- redis 链表操作
- 使用AngularJS创建应用的5个框架