D. Generating Sets
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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:

  1. Take any integer xi and multiply it by two, i.e. replace xi with 2·xi.
  2. 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.

Input

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.

Output

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.

Examples
input
5
1 2 3 4 5
output
4 5 2 3 1 
input
6
15 14 3 13 1 12
output
12 13 14 7 3 1 
input
6
9 7 13 17 5 11
output
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 贪心+优先队列的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

  6. 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C

    http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. <2013 10 18> Linux随机数生成器可能确实存在安全弱点

    生成随机数是密码学中的一项基本任务,是生成加密密钥和加密算法或加密协议所必不可少的.理想中的随机数是完美的,但实践中的随机数都是用伪随机数生成器(PRNG)生成,随机数的质量对安全性至关重要.安全专家 ...

  2. time 和 datetime 模块

    在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.我们运行“type(time.time( ...

  3. 图的遍历:DFS和BFS

    图的遍历一般由两者方式:深度优先搜索(DFS),广度优先搜索(BFS),深度优先就是先访问完最深层次的数据元素,而BFS其实就是层次遍历,每一层每一层的遍历. 1.深度优先搜索(DFS) 我一贯习惯有 ...

  4. (2)sql server 跨网段复制

    转自:http://www.cnblogs.com/gaizai/p/3328511.html 一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) ...

  5. Mac 安装Minikube

    环境信息: guoguo-MacBook-Pro-3:~ guoguo$ docker versionClient: Version:    17.12.0-ce API version:    1. ...

  6. NumPy基础知识:数组和矢量计算

    NumPy 的ndarray:一种多维数组对象 该对象是一个快速且灵活的大数据容器,可以利用这种数组对整个数据进行科学计算,语法跟标量元素之间的计算一样. 创建ndarray的方法: array函数: ...

  7. eclipse修改web项目部署路径 wtpwebapps webapps 的设置

    eclipse修改web项目部署路径 wtpwebapps   webapps  的设置,在添加完server------>tomcat后,到server控制台进行设置 eclipse默认的部署 ...

  8. js文件操作

    IE下 1. 写入 FileSystemObject可以将文件翻译成文件流. 第一步: 例: 复制代码代码如下: Var fso=new ActiveXObject(Scripting.FileSys ...

  9. Python操作SQLAlchemy

    Mysql环境: MySQL 一.概述什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建了一个 db 目录,称其为数据库 什么是 MySQL.Oracle.SQLite.Access.MS ...

  10. loadrunder之脚本篇——集合点设置

    1  作用 通过让多用户在同一时间点上进行并发操作来测试系统的并发处理的能力 2  实现 通过集合点函数来实现. 注意:集合点经常和事务结合起来使用.集合点只能插入到Action部分,vuser_in ...