hdu3949
XOR
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1648 Accepted Submission(s): 503
For each test case, the first line is an integer N(1<=N<=10000), the number of numbers below. The second line contains N integers (each number is between 1 and 10^18). The third line is a number Q(1<=Q<=10000), the number of queries. The fourth line contains Q numbers(each number is between 1 and 10^18) K1,K2,......KQ.
2
1 2
4
1 2 3 4
3
1 2 3
5
1 2 3 4 5
1
2
3
-1
Case #2:
0
1
2
3
-1
If you choose a single number, the result you get is the number you choose.
Using long long instead of int because of the result may exceed 2^31-1.
- #include<cstdio>
- #include<iostream>
- #include<cmath>
- #include<cstring>
- #include<algorithm>
- #define maxn 10005
- using namespace std;
- typedef long long int64;
- char ch;
- int T,q,n;
- int64 k,a[maxn];
- bool ok;
- void read(int &x){
- for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
- for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
- if (ok) x=-x;
- }
- void read(int64 &x){
- for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
- for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
- if (ok) x=-x;
- }
- void gauss(){
- int i,j,k;
- for (i=,k=;i>=;i--){
- for (j=k;j<=n&&!(a[j]&(1LL<<i));j++);
- if (j<=n){
- swap(a[k],a[j]);
- for (j=;j<=n;j++) if (j!=k&&(a[j]&(1LL<<i))) a[j]^=a[k];
- k++;
- }
- }
- sort(a+,a+n+),a[]=-;
- for (i=,j=;j<=n;j++) if (a[j]!=a[j-]) a[++i]=a[j];
- n=i;
- }
- int64 calc(int64 k){
- int64 ans=;
- int i=;
- if (a[]==) k--,i++;
- for (;i<=n&&k;i++,k>>=) if (k&) ans^=a[i];
- if (i>n&&k) return -;
- return ans;
- }
- int main(){
- read(T);
- for (int t=;t<=T;t++){
- read(n);
- for (int i=;i<=n;i++) read(a[i]);
- gauss();
- printf("Case #%d:\n",t);
- for (read(q);q;q--) read(k),printf("%I64d\n",calc(k));
- }
- return ;
- }
hdu3949的更多相关文章
- HDU3949 XOR (线性基)
HDU3949 XOR Problem Description XOR is a kind of bit operator, we define that as follow: for two bin ...
- 【线性基】hdu3949 XOR
给你n个数,问你将它们取任意多个异或起来以后,所能得到的第K小值? 求出线性基来以后,化成简化线性基,然后把K二进制拆分,第i位是1就取上第i小的简化线性基即可.注意:倘若原本的n个数两两线性无关,也 ...
- 【HDU3949】XOR
[题目大意] 给定一个数组,求这些数组通过异或能得到的数中的第k小是多少. 传送门:http://vjudge.net/problem/HDU-3949 [题解] 首先高斯消元求出线性基,然后将k按照 ...
- hdu3949 XOR xor高斯消元
XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu3949 异或空间 + 求矩阵的主元
给定n个整数,将数分解成01序列,由这n个01序列构成矩阵,这n个数构成线性空间,这就是异或空间 将这个矩阵高斯消元,求出t个主元,那么由着t个主元构成的线性空间里总共有2^t个数 设这t个数分别是a ...
- HDU3949 XOR
嘟嘟嘟 集训的时候发现自己不会线性基,就打算学一下. 这东西学了挺长时间,其实不是因为难,而是天天上午考试,下午讲题,结果晚上就开始颓了. 今天总算是有大块的时间好好学了一遍. 这里推荐menci大佬 ...
- HDU3949:XOR——题解
http://acm.hdu.edu.cn/showproblem.php?pid=3949 求n个数的异或和第k小. 参考:https://blog.sengxian.com/algorithms/ ...
- [hdu3949]XOR(线性基求xor第k小)
题目大意:求xor所有值的第k小,线性基模板题. #include<cstdio> #include<cstring> #include<algorithm> #i ...
- hdu3949(线性基,求第k小的异或和
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 XOR Time Limit: 2000/1000 MS (Java/Others) Me ...
随机推荐
- [Locked] Missing Ranges
Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive ...
- Redis 与 Memcached 的区别
[转]Redis 与 Memcached 的区别 传统 MySQL + Memcached 架构遇到的问题 实际上 MySQL 是适合进行海量数据存储的,通过 Memcached 将热点数据加 ...
- Visual studio 2008 的语法高亮插件 NShader
前段时间一直在使用matlab,今天需要使用vs2008,而用惯了matlab,习惯了其中一项选中变量高亮的设置,突然回来使用VS,感到各种不适应,顿时想到了一个词:矫情 呵呵,于是在网上找各种插件, ...
- Nginx优化具体,应对高并发
nginx指令中的优化(配置文件) worker_processes 8; nginx进程数,建议依照cpu数目来指定.一般为它的倍数. worker_cpu_affinity 00000001 ...
- CentOS 6.4的安装--史上最全-CRPER木木
安装工具及软件: VmwareWorkstation9 CentOS-6.4-x86_64-LiveCD Vmware初始设置: 刚装好的VMWARE启动后,虽说默认已经设置好基础 ...
- 三星笔记本R428安装xp win7双系统,切换系统重启才能进入系统解决办法。
三星笔记本 XP win7 双系统切换重启解决方法 三星笔记本有个奇怪的现象,就是装有XP和win7双系统 xp切换到win7.进系统是会重启一次,并且bios回复光驱为第一启动项,win7切换 ...
- PHP开发安全之近墨者浅谈(转)
==过滤输入/输出转义 过滤是Web应用安全的基础.它是你验证数据合法性的过程.通过在输入时确认对所有的数据进行过滤,你可以避免被污染(未过滤)数据在你的程序中被误信及误用.大多数流行的PHP应用的漏 ...
- PHP安全编程:不要让不相关的人看到报错信息(转)
没有不会犯错的开发者,PHP的错误报告功能可以协助你确认和定位这些错误,可以提供的这些错误的详细描述,但如果被恶意攻击者看到,这就不妙了.不能让大众看到报错信息,这一点很重要.做到这一点很容易,只要关 ...
- 网络环境场景以及模拟工具netem
网络环境场景包括: 延迟(Lag),把数据包缓存一段时间后再发出,这样能够模拟网络延迟的状况. 掉包(Drop),随机丢弃一些数据. 节流(Throttle),把一小段时间内的数据拦截下来后再在之后的 ...
- Android(java)学习笔记217:开发一个多界面的应用程序之清单文件
清单文件的重要参数: <intent-filter> 代表的应用程序的入口界面 <action android:name=&quo ...