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. 如何使用JDBC链接数据库

    1.加载数据库驱动 不同的数据库加载的驱动不一样 Class.forName(com.MySQL.jdbc.Driver) Class.forName(oracle.jdbc.driver.Oracl ...

  2. mysql dba系统学习(6)二进制日志binlog之二

    MySQL 5.5 中对于二进制日志 (binlog) 有 3 种不同的格式可选:Mixed,Statement,Row,默认格式是 Statement.总结一下这三种格式日志的优缺点.MySQL R ...

  3. 配置Maven环境并创建简单的web项目步骤

    Maven的介绍 主要包含以下三个内容: 1.POM(Project Object Model):即An xml file(pom.xml):依赖管理.生命周期和插件的需要等都在pom.xml文件中完 ...

  4. git 远程版本库,github提供服务原理,git自动更新发送邮件

    1.安装好Linux,安装好Git(192.168.1.239) 2.创建一个用户zph(让此用户提供git on server),密码设置为12345678 # useradd zph # pass ...

  5. 非常简单的数据,支持excel表格下载功能

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  6. $.ajx的用法

    $.ajax({type:'post',//可选geturl:'action.php',//这里是接收数据的PHP程序data:'data='dsa'',//传给PHP的数据,多个参数用&连接 ...

  7. Jquery之树形插件

    1.DynaTree (推荐使用,说明文档以及样例在下载的压缩包里\doc\samples.html) DynaTree 是一个优化的动态jQuery树查看插件,它只在需要时才创建DOM元素.支持ch ...

  8. Elasticsearch 聚合

    桶(bucket)聚合 满足条件的结果集合.桶可以嵌套 标(metric)聚合 满足条件的结果集合的一些指标.如count,max等.

  9. SVN在eclipse的整合应用

    目前很多的Java.Flex.Android开发人员是用eclipse作为开发工具的,本文主要介绍SVN在eclipse平台中的整合应用. 我的eclipse版本是Version: 3.4.2.本身没 ...

  10. Application Pool