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. L2-004. 这是二叉搜索树吗?

    L2-004. 这是二叉搜索树吗? 题目链接:https://www.patest.cn/contests/gplt/L2-004 这题我的方法是先递归判定是不是二叉搜索树(镜像),再建树输出. 代码 ...

  2. js--性能优化(转)

    前言 一直在学习javascript,也有看过<犀利开发Jquery内核详解与实践>,对这本书的评价只有两个字犀利,可能是对javascript理解的还不够透彻异或是自己太笨,更多的是自己 ...

  3. PHP导出一个txt文本文件

    <?php Header( "Content-type:   application/octet-stream "); Header( "Accept-Ranges ...

  4. java 读取excel 正常 xls

    package com.sun.test; import java.io.BufferedInputStream;import java.io.File;import java.io.FileInpu ...

  5. Struts对输入数据的校验

    当我们在登录或者是注册时需要对用户输入的数据验证,以前都是浏览器传送数据到后台,后台对数据进行校验,如果有错误就带着错误信息转发带登录或者注册页面, struts可以简便的对输入数据进行校验 首先我们 ...

  6. ubuntu 调试库

    .安装带有调试信息的libc: sudo apt-get install libc6-dbg .下载libc源码 a.选定一个放置源码的目录并进入,如 /home/kent/dev-os/libc6- ...

  7. 正则表达式协助实现排序&&邮箱验证

    /** 将IP地址按照字符串的自然顺序排序,只要让他们的每段的位数都是3就可以. 1.按照每一段需要的最多的0进行补齐,那么每一段就会至少保证有3位. 2.将每一段都保留3位.这样所有的ip地址都是每 ...

  8. java读写串口

    http://blog.csdn.net/xxyy888/article/details/8946046

  9. 微信web开发工具

    http://mp.weixin.qq.com/wiki/10/e5f772f4521da17fa0d7304f68b97d7e.html#.E4.B8.8B.E8.BD.BD.E5.9C.B0.E5 ...

  10. 工作中用到的简单linux命令

    1.rpm包查询.卸载.安装: rpm包查询 rpm -q 包名(不带版本号.后缀等)  q----query rpm包卸载 rpm -e 包名(不带版本号.后缀等)e----erase rpm包安装 ...