传送门

题意:

  给出一个序列,输出每个数x对应的一个ans,要求ans在数列中,并且ans & x  = 0;数列的每个数小于(4e6)

思路:

  这道题的方向比较难想。想到了就比较轻松了,可以这样考虑,如果(11011)2的答案知道了,那么(11001)2,(11000)2等的答案其实就是那个答案。

  注意 (1<<22)-1 ,所以直接从最大的向下枚举,对于每个数,看看把0位变成1位后是否能有答案。

  1. #include <algorithm>
  2. #include <iterator>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <iomanip>
  7. #include <bitset>
  8. #include <cctype>
  9. #include <cstdio>
  10. #include <string>
  11. #include <vector>
  12. #include <stack>
  13. #include <cmath>
  14. #include <queue>
  15. #include <list>
  16. #include <map>
  17. #include <set>
  18. #include <cassert>
  19.  
  20. using namespace std;
  21. #define lson (l , mid , rt << 1)
  22. #define rson (mid + 1 , r , rt << 1 | 1)
  23. #define debug(x) cerr << #x << " = " << x << "\n";
  24. #define pb push_back
  25. #define pq priority_queue
  26.  
  27. typedef long long ll;
  28. typedef unsigned long long ull;
  29. //typedef __int128 bll;
  30. typedef pair<ll ,ll > pll;
  31. typedef pair<int ,int > pii;
  32. typedef pair<int,pii> p3;
  33.  
  34. //priority_queue<int> q;//这是一个大根堆q
  35. //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
  36. #define fi first
  37. #define se second
  38. //#define endl '\n'
  39.  
  40. #define OKC ios::sync_with_stdio(false);cin.tie(0)
  41. #define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
  42. #define REP(i , j , k) for(int i = j ; i < k ; ++i)
  43. #define max3(a,b,c) max(max(a,b), c);
  44. #define min3(a,b,c) min(min(a,b), c);
  45. //priority_queue<int ,vector<int>, greater<int> >que;
  46.  
  47. const ll mos = 0x7FFFFFFF; //
  48. const ll nmos = 0x80000000; //-2147483648
  49. const int inf = 0x3f3f3f3f;
  50. const ll inff = 0x3f3f3f3f3f3f3f3f; //
  51. const int mod = 1e9+;
  52. const double esp = 1e-;
  53. const double PI=acos(-1.0);
  54. const double PHI=0.61803399; //黄金分割点
  55. const double tPHI=0.38196601;
  56.  
  57. template<typename T>
  58. inline T read(T&x){
  59. x=;int f=;char ch=getchar();
  60. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  61. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  62. return x=f?-x:x;
  63. }
  64.  
  65. /*-----------------------showtime----------------------*/
  66.  
  67. const int maxn = (<<) - ;
  68. int a[maxn],dp[maxn];
  69. int main(){
  70. int n; scanf("%d", &n);
  71.  
  72. memset(dp, -, sizeof(dp));
  73. for(int i=; i<=n; i++) scanf("%d", &a[i]), dp[maxn & (~a[i])] = a[i];
  74.  
  75. for(int i=maxn; i>=; i--){
  76. if(dp[i] > ) continue;
  77.  
  78. for(int j=; j<; j++){
  79. if((i & (<< j)) == && dp[i^(<<j)] > ){
  80. dp[i] = dp[i^(<<j)];
  81. break;
  82. }
  83. }
  84. }
  85.  
  86. for(int i=; i<=n; i++) printf("%d ", dp[a[i]]);
  87. puts("");
  88. return ;
  89. }

CFdiv2 165E. Compatible Numbers 子集枚举的更多相关文章

  1. Codeforces 165E Compatible Numbers(二进制+逆序枚举)

    E. Compatible Numbers time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  2. CodeForces 165E Compatible Numbers(位运算 + 好题)

    wo integers x and y are compatible, if the result of their bitwise "AND" equals zero, that ...

  3. 【最小生成树+子集枚举】Uva1151 Buy or Build

    Description 平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此,你可以新建一些边,费用等于两个端点的欧几里得距离的平方. 另外还有q(0<=q< ...

  4. UVA11825 黑客的攻击 Hackers' Crackdown 状压DP,二进制,子集枚举

    题目链接Click Here [题目描述] 假如你是一个黑客,侵入了一个有着\(n\)台计算机(编号为\(1.2.3....n\))的网络.一共有\(n\)种服务,每台计算机都运行着所有服务.对于每台 ...

  5. Codeforces 165 E. Compatible Numbers【子集前缀和】

    LINK 题目大意 给你一个数组,问你数组中的每个数是否可以在数组里面找到一个数和他and起来是0,如果可以就输出这个数,否则就输出-1 思路 首先很显然的是可以考虑找到每个数每一位都取反的数的子集 ...

  6. UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  7. BZOJ 1688: Disease Manangement (子集枚举)

    Disease Manangement Q - 枚举子集 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d &a ...

  8. uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

    题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...

  9. Sheldon Numbers GYM -- 枚举

    Sheldon Numbers GYM 题意:定义Sheldon Number为其二进制数是ABA……ABA型的或者ABAB……AB的,其中A全为1,B全为0(A>0, B>0),问[m, ...

随机推荐

  1. jmeter Linux环境执行总报错 cannot allocate memory

    1.windows环境写好的测试用例,执行没有问题,在Linux环境跑总是报错,提示如下 cannot allocate memory 2.一开始以为是哪块设置有问题,因为脚本里边有设置邮件自动发送, ...

  2. Charles(Windows/Android)入门使用

    一. 介绍以及下载(windows) Charles是一个HTTP代理/HTTP监视器/反向代理,使开发人员能够查看其机器和Internet之间所有HTTP和SSL/HTTPS流量,这包括请求,响应和 ...

  3. 【Spring】org.springframework.web.context.ContextLoaderListen 报错

    详细信息如下: org.apache.catalina.core.StandardContext.listenerStart Error configuring application listene ...

  4. 【iOS】使用 CocoaPods 导入文件没有提示

    解决方法: 选择工程的 TAEGETS -> Build Settings, 找到 Search Paths 下的 User Header Search Paths选项,如图所示: 点击 “+” ...

  5. strus 上传文件

    (1) action代码 package comSys.struts.articleManager; import java.io.File; import java.io.FileInputStre ...

  6. django数据库事务

    数据库原子操作 举个例子: 一个消费者在一个商户里刷信用卡消费,交易正常时,银行在消费者的账户里减去相应的款项,在商户的帐户加上相应的款项.但是如果银行从消费者的账户里扣完钱之后,还未在商户的帐户里加 ...

  7. 2、大型项目的接口自动化实践记录--接口测试简介及RequestsLibrary关键字简介

    1.接口测试简介 1)先简单介绍下接口测试,那么什么是接口测试呢? 百科的回答:接口测试是测试系统组件间接口的一种测试.接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点. 看起来有 ...

  8. Broadcast 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  9. CSS: hack 方式一览

    本文引自:http://blog.csdn.net/freshlover/article/details/12132801 什么是CSS hack 由于不同厂商的流览器或某浏览器的不同版本(如IE6- ...

  10. MySQL InnoDB Cluster介绍

    目录 一.MySQL InnoDB Cluster介绍 二.环境准备 三.将MGR节点加入MySQL Cluster 四.问题汇总 五.性能测试 六.个人总结 一.MySQL InnoDB Clust ...