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,集合Y有一些1e9以内的正整数组成,求一个集合X,拥有和集合Y一多的元素,每一个在X集合中的元素可以*2或者*2+1,且进行任意次操作之后变为Y集合,求一种X集合使得X集合中的最大值最小

sol:显然贪心具有正确性,我们每次选取一个最大的数字,看它/2之后是否冲突,如果冲突就再/2,一直到不冲突,若一直冲突就结束。
用队来维护,复杂度O(n^(logn*logx,i))

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
#include<ctime>
#include<cstring>
#include<queue>
#include<set>
#define yyj(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define llg long long
#define maxn 200010
using namespace std;
llg i,j,k,n,m,x,a[maxn]; struct node
{
long long val;
bool operator <(const node &rhs) const
{
return val < rhs.val;
}
}; priority_queue<node> q;
set <node> s; int main()
{
// yyj("d");
cin>>n;
node qq;
for (i=;i<=n;i++)
{
scanf("%I64d",&x);
qq.val=x;
s.insert(qq);
q.push(qq);
}
node w;
while ()
{
qq=q.top();
w.val=qq.val/;
if (w.val==) break;
while (s.find(w)!=s.end() && w.val/!=) w.val/=;
while (s.find(w)==s.end())
{
s.erase(qq);
s.insert(w);
q.pop();
q.push(w);
qq=q.top(); w.val=qq.val/;
if (w.val==) break;
while (s.find(w)!=s.end() && w.val/!=) w.val/=;
}
break;
}
while (!q.empty())
{
cout<<q.top().val<<" ";
q.pop();
}
return ;
}

Codeforces 722D. Generating Sets的更多相关文章

  1. codeforces 722D Generating Sets 【优先队列】

    You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive ...

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

  3. CF722D. Generating Sets[贪心 STL]

    D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Generating Sets 贪心

    H - Generating Sets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  5. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心+优先队列

    D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. [codeforces722D]Generating Sets

    [codeforces722D]Generating Sets 试题描述 You are given a set Y of n distinct positive integers y1, y2, . ...

  7. D. Generating Sets 解析(思維)

    Codeforce 722 D. Generating Sets 解析(思維) 今天我們來看看CF722D 題目連結 題目 略,請直接看原題 前言 真的是沒想到... @copyright petje ...

  8. 【53.57%】【codeforces 722D】Generating Sets

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. Codeforces 486D Valid Sets:Tree dp【n遍O(n)的dp】

    题目链接:http://codeforces.com/problemset/problem/486/D 题意: 给你一棵树,n个节点,每个节点的点权为a[i]. 问你有多少个连通子图,使得子图中的ma ...

随机推荐

  1. PHP部分资料

    完善PHP登陆注册页面,同时连接mysql数据库 http://blog.csdn.net/tianlu1677/article/details/7765889/ PHP 附录 : 用户注册与登录完整 ...

  2. [总结] I/O输入,输出

    I/O输入,输出第一:先判断到底是输入还是输出,站在程序的立场第二:判断是传递字节,还是字符,决定管道粗细,字节流是最基本的数据输出管道.字符类型管道专门用来传送文本数据.Java流的四大父类:1.字 ...

  3. Excel标题与索引的对应关系

    /// <summary> /// 返回对应标题的索引 /// </summary> /// <param name="columnTitle"> ...

  4. 【皇甫】☀Hibernate入门

    说说我们最近的一些事 二期已经过去了,下面迎接的就是二年,据原老师讲解,我们10月份就开始陆续找工作了,虽然他说我们找工作不是问题,可每个人都有自知之明,我也知道我所处的位置,所以我清楚我要怎么做,我 ...

  5. 个人训练记录-赛码"bestcoder"杯中国大学生程序设计冠军赛

    A.Movie 题意是给n个线段,要求求出是否存在三个不相交的线段,是的话输出yes,否则输出no.根据贪心的想法,可以先找出右端点r'最小的线段,他是三条线段中最左的那条,再找出左端点l'最大的线段 ...

  6. sublime text3 前端编译神器,浏览器实时显示

    前端编译器有很多,Dreamweaver,sublime text ,webstorm,但在使用之后感觉sublime text3就是前端的编译神器 首先sublime text3最好使用英文原版,虽 ...

  7. WBS功能分解

    WBS功能分解表格如下: 功能 子功能 二级子功能 预计花费时间 (小时) 实际花费时间(小时) 地图显示跑道 制作地图 获得开发权限key 1 2 将sdk导入程序 0.5 1   调试程序 1 2 ...

  8. 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别

    [<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...

  9. Javascript之confirm的用法

    confirm函数 confirm函数用于提供确认功能,它首先显示给定的message参数所包含的信息,并提供两个可选择的回答“ok”和“cancel”,然后等待用户选择其中的一个.如果用户选择“ok ...

  10. vim如何配置go语言环境

    go语言没有如source insight般优秀的编辑器,试用了多种,vim算最好的,其次可以用liteide(有反查变量函数引用点.修改行变色功能),两者可配合使用. 更新:最好的是idea+go插 ...