Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心+优先队列
2 seconds
256 megabytes
standard input
standard output
You are given a set Y of n distinct positive integers y1, y2, ..., yn.
Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X:
- Take any integer xi and multiply it by two, i.e. replace xi with 2·xi.
- Take any integer xi, multiply it by two and add one, i.e. replace xi with 2·xi + 1.
Note that integers in X are not required to be distinct after each operation.
Two sets of distinct integers X and Y are equal if they are equal as sets. In other words, if we write elements of the sets in the array in the increasing order, these arrays would be equal.
Note, that any set of integers (or its permutation) generates itself.
You are given a set Y and have to find a set X that generates Y and the maximum element of X is mininum possible.
The first line of the input contains a single integer n (1 ≤ n ≤ 50 000) — the number of elements in Y.
The second line contains n integers y1, ..., yn (1 ≤ yi ≤ 109), that are guaranteed to be distinct.
Print n integers — set of distinct integers that generate Y and the maximum element of which is minimum possible. If there are several such sets, print any of them.
5
1 2 3 4 5
4 5 2 3 1
6
15 14 3 13 1 12
12 13 14 7 3 1
6
9 7 13 17 5 11
4 5 2 6 3 1
题意:给你一个集合y,集合x可以进行1,2的若干’烧‘操作,求x,x需要满足x的最大值最小;
思路:每次取最大的往下改变,不能变就存答案;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
priority_queue<int>q;
int ans[N],flag,a[N],n;
map<int,int>m;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%d",&a[i]),m[a[i]]=,q.push(a[i]);
while(!q.empty())
{
int v=q.top();
q.pop();
int num=v;
while(num)
{
if(!m[num])break;
num>>=;
}
if(num&&!m[num])
{
q.push(num);
m[v]=;
m[num]=;
}
else
ans[flag++]=v;
}
for(int i=;i<n;i++)
printf("%d ",ans[i]);
return ;
}
Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心+优先队列的更多相关文章
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列
		A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ... 
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题
		B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ... 
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
		A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ... 
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)
		题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ... 
- 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D
		http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ... 
- 线段树  或者 并查集   Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C
		http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ... 
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心
		D. Generating Sets 题目连接: http://codeforces.com/contest/722/problem/D Description You are given a set ... 
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)  C. Destroying Array 带权并查集
		C. Destroying Array 题目连接: http://codeforces.com/contest/722/problem/C Description You are given an a ... 
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题
		A. Broken Clock 题目连接: http://codeforces.com/contest/722/problem/A Description You are given a broken ... 
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array
		C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ... 
随机推荐
- 二维码及二维码接合短URL的应用
			二维码 1.什么是二维码? 二维条形码,最早发明于日本,它是用某种特定的几何图形按一定规律在平面(二维方向上)分布的黑白相间的图形记录数据符号信息的,在代码编制上巧妙地利用构成计算机内部逻辑基础的“0 ... 
- Unity字体文件放Resources和打成ab对比
			情况一:公共字体打成ab的时候,加载A界面的时候加载了font的ab,卸载A和font的ab后,接着加载B界面,加载了font的ab,卸载B和font的ab,这时候字体对应的asset会在内存里有两份 ... 
- MySQL中Index Condition Pushdown(ICP)优化
			在MySQL 5.6开始支持的一种根据索引进行查询的优化方式.之前的MySQL数据库版本不支持ICP,当进行索引查询是,首先根据索引来查找记录,然后在根据WHERE条件来过滤记录.在支持ICP后,My ... 
- Linux中的欢迎信息
			本地终端欢迎信息 /etc/issue \d 显示当前系统日期 \s 显示操作系统名称 \l 显示终端的终端号,这个比较常用 \m 显示硬件体系结构,如i386.i68 ... 
- 使用git工具上传项目到github步骤
			这里记录一下上传项目到github的步骤.使用的工具是Git bash. 1.登陆github,没有账户就注册一个,新建一个Repository(仓库). 2.绑定用户. 因为Git是分布式版本控制系 ... 
- 字符串之strcmp
			功能:比较两个字符串的ascII码大小 输入:两个字符串 返回值:相等为0,大于为大于零,小于为小于零 #include <iostream> #include <assert.h& ... 
- 003 F-47创建预付定金请求检查增强-20150819.docx
			Enhancement SE38:LEINRF26 操作F-47,预付定金请求回车时,检查输入的采购订单项目发票视图,预付定金% 栏位,若为空,则报错,不为空可继续. 检查逻辑:检查采购凭证项 ... 
- 如何用好 Google 等搜索引擎
			1: 双引号短语搜索2: 减号减号前面必须是空格,减号后面没有空格,紧跟着需要排除的词例如:搜索 -引擎返回的则是包含“搜索”这个词,却不包含“引擎”这个词的结果3: 星号RE,通配符4: intit ... 
- selection   createTextRange  setSelectionRange
			http://www.cnblogs.com/rainman/archive/2011/02/27/1966482.html http://www.zhangxinxu.com/wordpress/2 ... 
- 算法寒假实习面试经过之 滴滴(电话一面二面   offer)
			一面:1h 介绍比赛项目. lr与xgb的区别? xgb 为什么不用归一化,onehot? xgb 与 gbdt的区别. 做这些比赛你们的优势在哪,既然全是相同的套路. RCNN的原理, CNN的原理 ... 
