CFdiv2 165E. Compatible Numbers 子集枚举
题意:
给出一个序列,输出每个数x对应的一个ans,要求ans在数列中,并且ans & x = 0;数列的每个数小于(4e6)
思路:
这道题的方向比较难想。想到了就比较轻松了,可以这样考虑,如果(11011)2的答案知道了,那么(11001)2,(11000)2等的答案其实就是那个答案。
注意 (1<<22)-1 ,所以直接从最大的向下枚举,对于每个数,看看把0位变成1位后是否能有答案。
- #include <algorithm>
- #include <iterator>
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- #include <iomanip>
- #include <bitset>
- #include <cctype>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <stack>
- #include <cmath>
- #include <queue>
- #include <list>
- #include <map>
- #include <set>
- #include <cassert>
- using namespace std;
- #define lson (l , mid , rt << 1)
- #define rson (mid + 1 , r , rt << 1 | 1)
- #define debug(x) cerr << #x << " = " << x << "\n";
- #define pb push_back
- #define pq priority_queue
- typedef long long ll;
- typedef unsigned long long ull;
- //typedef __int128 bll;
- typedef pair<ll ,ll > pll;
- typedef pair<int ,int > pii;
- typedef pair<int,pii> p3;
- //priority_queue<int> q;//这是一个大根堆q
- //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
- #define fi first
- #define se second
- //#define endl '\n'
- #define OKC ios::sync_with_stdio(false);cin.tie(0)
- #define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
- #define REP(i , j , k) for(int i = j ; i < k ; ++i)
- #define max3(a,b,c) max(max(a,b), c);
- #define min3(a,b,c) min(min(a,b), c);
- //priority_queue<int ,vector<int>, greater<int> >que;
- const ll mos = 0x7FFFFFFF; //
- const ll nmos = 0x80000000; //-2147483648
- const int inf = 0x3f3f3f3f;
- const ll inff = 0x3f3f3f3f3f3f3f3f; //
- const int mod = 1e9+;
- const double esp = 1e-;
- const double PI=acos(-1.0);
- const double PHI=0.61803399; //黄金分割点
- const double tPHI=0.38196601;
- template<typename T>
- inline T read(T&x){
- x=;int f=;char ch=getchar();
- while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
- while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
- return x=f?-x:x;
- }
- /*-----------------------showtime----------------------*/
- const int maxn = (<<) - ;
- int a[maxn],dp[maxn];
- int main(){
- int n; scanf("%d", &n);
- memset(dp, -, sizeof(dp));
- for(int i=; i<=n; i++) scanf("%d", &a[i]), dp[maxn & (~a[i])] = a[i];
- for(int i=maxn; i>=; i--){
- if(dp[i] > ) continue;
- for(int j=; j<; j++){
- if((i & (<< j)) == && dp[i^(<<j)] > ){
- dp[i] = dp[i^(<<j)];
- break;
- }
- }
- }
- for(int i=; i<=n; i++) printf("%d ", dp[a[i]]);
- puts("");
- return ;
- }
CFdiv2 165E. Compatible Numbers 子集枚举的更多相关文章
- Codeforces 165E Compatible Numbers(二进制+逆序枚举)
E. Compatible Numbers time limit per test 4 seconds memory limit per test 256 megabytes input standa ...
- CodeForces 165E Compatible Numbers(位运算 + 好题)
wo integers x and y are compatible, if the result of their bitwise "AND" equals zero, that ...
- 【最小生成树+子集枚举】Uva1151 Buy or Build
Description 平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此,你可以新建一些边,费用等于两个端点的欧几里得距离的平方. 另外还有q(0<=q< ...
- UVA11825 黑客的攻击 Hackers' Crackdown 状压DP,二进制,子集枚举
题目链接Click Here [题目描述] 假如你是一个黑客,侵入了一个有着\(n\)台计算机(编号为\(1.2.3....n\))的网络.一共有\(n\)种服务,每台计算机都运行着所有服务.对于每台 ...
- Codeforces 165 E. Compatible Numbers【子集前缀和】
LINK 题目大意 给你一个数组,问你数组中的每个数是否可以在数组里面找到一个数和他and起来是0,如果可以就输出这个数,否则就输出-1 思路 首先很显然的是可以考虑找到每个数每一位都取反的数的子集 ...
- UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)
Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...
- BZOJ 1688: Disease Manangement (子集枚举)
Disease Manangement Q - 枚举子集 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d &a ...
- uva 11825 Hackers' Crackdown (状压dp,子集枚举)
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...
- Sheldon Numbers GYM -- 枚举
Sheldon Numbers GYM 题意:定义Sheldon Number为其二进制数是ABA……ABA型的或者ABAB……AB的,其中A全为1,B全为0(A>0, B>0),问[m, ...
随机推荐
- jmeter Linux环境执行总报错 cannot allocate memory
1.windows环境写好的测试用例,执行没有问题,在Linux环境跑总是报错,提示如下 cannot allocate memory 2.一开始以为是哪块设置有问题,因为脚本里边有设置邮件自动发送, ...
- Charles(Windows/Android)入门使用
一. 介绍以及下载(windows) Charles是一个HTTP代理/HTTP监视器/反向代理,使开发人员能够查看其机器和Internet之间所有HTTP和SSL/HTTPS流量,这包括请求,响应和 ...
- 【Spring】org.springframework.web.context.ContextLoaderListen 报错
详细信息如下: org.apache.catalina.core.StandardContext.listenerStart Error configuring application listene ...
- 【iOS】使用 CocoaPods 导入文件没有提示
解决方法: 选择工程的 TAEGETS -> Build Settings, 找到 Search Paths 下的 User Header Search Paths选项,如图所示: 点击 “+” ...
- strus 上传文件
(1) action代码 package comSys.struts.articleManager; import java.io.File; import java.io.FileInputStre ...
- django数据库事务
数据库原子操作 举个例子: 一个消费者在一个商户里刷信用卡消费,交易正常时,银行在消费者的账户里减去相应的款项,在商户的帐户加上相应的款项.但是如果银行从消费者的账户里扣完钱之后,还未在商户的帐户里加 ...
- 2、大型项目的接口自动化实践记录--接口测试简介及RequestsLibrary关键字简介
1.接口测试简介 1)先简单介绍下接口测试,那么什么是接口测试呢? 百科的回答:接口测试是测试系统组件间接口的一种测试.接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点. 看起来有 ...
- Broadcast 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- CSS: hack 方式一览
本文引自:http://blog.csdn.net/freshlover/article/details/12132801 什么是CSS hack 由于不同厂商的流览器或某浏览器的不同版本(如IE6- ...
- MySQL InnoDB Cluster介绍
目录 一.MySQL InnoDB Cluster介绍 二.环境准备 三.将MGR节点加入MySQL Cluster 四.问题汇总 五.性能测试 六.个人总结 一.MySQL InnoDB Clust ...