275. To xor or not to xor(高斯消元求最大亦或值)
来源:互联网 发布:soundhound mac 编辑:程序博客网 时间:2024/06/08 13:39
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=275
275. To xor or not to xor
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
memory limit per test: 65536 KB
input: standard
output: 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
【解析】:
题意:从输入的n个数中,选出一部分,亦或起来,使得亦或值最大。
看了别人的代码解析,还是理解不了,模仿着写了个代码,虽然AC了。但是还是不理解到底是怎么做到的。
(等我懂了再补解析吧。望同志能给指点,评论区指点迷津)
【代码】:
#include <stdio.h>#include <string.h>#define mset(a,i) memset(a,i,sizeof(a))using namespace std;typedef long long ll;ll a[64];bool vis[105];int main(){int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%lld",&a[i]);a[n]=0x7fffffffffffffff;ll ans=0;mset(vis,0);for(int i=62;i>=0;i--)//从最高位开始选{int flag=1;for(int j=0;j<n;j++)//寻找该位是1的数,去亦或进其他数里{if(flag&&!vis[j]&&(a[j]&(1ll<<i)))//a[j]没有选&&该位为1{vis[j]=1;for(int k=0;k<=n;k++)if(k!=j&&(a[k]&(1ll<<i)))a[k]^=a[j];flag=0;}}if(flag==0||(flag&&(a[n]&(1ll<<i))==0))ans+=(1ll<<i);}printf("%lld\n",ans);return 0;}
阅读全文
0 0
- 275. To xor or not to xor(高斯消元求最大亦或值)
- To xor or not to xor 高斯消元求异或
- sgu275:To xor or not to xor(最大异或和)
- To xor or not to xor SGU
- SGU 275. To xor or not to xor(高斯消元)
- sgu275--To xor or not to xor(高斯消元问题5,子序列异或的最大和)
- SGU275. To xor or not to xor(高斯消元求N个数中任取M个数求得异或最大值)
- 异或思维题--to xor or not to xor nkoj3734
- SGU_275 To xor or not to xor gauss
- SGU 275 To xor or not to xor
- sgu275 To xor or not to xor ----高斯消元复习
- 【SGU 275】 To xor or not to xor
- [SGU275]To xor or not to xor 枚举+高斯消元
- 高斯消元 SGU275 To xor or not to xor
- SGU 275 To xor or not to xor (高斯消元)
- SGU 275 To xor or not to xor (高斯消元)
- 【高斯消元】[SGU275]To xor or not to xor
- 【高斯消元】[SGU275]To xor or not to xor
- 配置wireshark和tshark解析MMS协议
- 风口之下,猪都能飞。当今中国股市牛市,真可谓“错过等七年”。 给你一个回顾历史的机会,已知一支股票连续n天的价格走势,以长度为n的整数数组表示,数组中第i个元素(prices[i])代表该股票第i天
- 快速搜索手机上某文件
- redis 数据类型详解+redis适用场景场合
- 一个项目的工作流程
- 275. To xor or not to xor(高斯消元求最大亦或值)
- exit(0)与exit(1)、return区别
- Award BIOS,AWI BIOS,Phoenix BIOS,兼容BIOS的部分警报的含义
- Eclipse hibernate Tools下载
- .NET并行计算和并发3-Invoke
- 攻击容器集群管理平台
- [leetcode]142. Linked List Cycle II@Java解题报告
- MFC学习笔记01-(_T()与L的区别)
- 软件测试过程中有哪些风险?