http://codeforces.com/contest/722/problem/D

题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某个元素*2+1

问:找到一个X集合,里面的元素与Y的元素可以相互转换,且X的max要尽量小。

思路:二分答案找就好了。从Y开始进入,不需要考虑奇偶数,反正每次都/2就行了。

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = + ;
int a[maxn], ans[maxn];
int n; bool check(int maxval){
map<int, int> m;
int cnt = ;
for (int i = ; i <= n; i++){
int myval = a[i];
while (myval && (myval > maxval || m.count(myval)))
myval /= ;///除以2就好了,貌似并不需要考虑+1
if (myval == ) return ;
m[myval] = ;
ans[i] = myval;
}
return ;
} int main(){
cin >> n;
int l = , r = ;
for (int i = ; i <= n; i++){
scanf("%d", a + i); r = max(a[i], r);
}
while (l < r){
int mid = (l + r) / ;
if (check(mid)){
r = mid;
}
else l = mid + ;
}
check(l);
for (int i = ; i <= n; i++){
printf("%d ", ans[i]);
}
return ;
}

二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D的更多相关文章

  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) C

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

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

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

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

  9. 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. BBED跳过归档

    通过BBED 跳过归档,以当前数据库 8号文件为例: SQL; FILE# NAME ---------- ---------------------------------------------- ...

  2. lt&gt&eq

    lt:less than,小于 gt:greater than,大于 eq:equal,等于 le:less equal,小于等于 ge:greater than,大于等于

  3. 第七十三节,css盒模型

    css盒模型 学习要点: 1.元素尺寸 2.元素内边距 3.元素外边距 4.处理溢出 本章主要探讨HTML5中CSS盒模型,学习怎样了解元素的外观配置以及文档的整体布局. 一.元素尺寸 CSS盒模型中 ...

  4. ssh: scp命令

    scp 复制命令 Eg. -r /tmp/q1 root@[::]/home 1.命令格式: scp [参数] [原路径] [目标路径] 2.命令功能: scp是 secure copy的缩写, sc ...

  5. 关于Unity项目中创建项目遇到的一些问题

    1.Unity调用Android的方法默认不是在UI线程执行,所以在Android上写一些页面的重绘的方法,让Unity去调用时,注意要在Android中添加对应的runOnUiThread才可以: ...

  6. 浙江大学Pat 1036 题解

    1036. Boys vs Girls (25) This time you are asked to tell the difference between the lowest grade of ...

  7. JSP中 JSTL

    1,JSTL是JSP的标准标签库的简称,JSP标准标签库包括5类:分别是核心标签库,国际化标签库,SQL标签库,XML标签库,函数标签库: 2,常用的就是核心标签库和SQL标签库: 核心标签库:前置名 ...

  8. centos 6 安装docker

    安装 Fedora EPEL 1.yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarc ...

  9. Visual Studio 2010/2013 UTF8编码调试时显示中文

    VisualStudio 2010 SP1环境 1.设置string默认编码为utf8,只需要在文件头部加入以下代码 #pragma execution_character_set("utf ...

  10. EnumPrinters用法

    看API描述,不怎么理解,还是在网上找到用法,记载一下: 1: DWORD dwNeeded = 0, dwNum = 0; 2: EnumPrinters(PRINTER_ENUM_LOCAL, N ...