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. 拔高课程_day14_课堂笔记

    今日大纲 Redis的持久化 Redis的主从 Redis的集群 mysql 优化 tomcat优化 Redis的持久化 持久化 持久化,就是将数据保存到磁盘,机器宕机或者重启数据不丢失,如果存储到内 ...

  2. JavaBean 反射机制实现自动配置数据

    声明:该版本是没完成的.该博文只做记录代码用 String memberType(String name) throws Exception { return getType(getClass().g ...

  3. springMVC+Java验证码完善注册功能

    这篇文章简单的写了一个java验证码,为之前写过的springMVC注册功能加上验证码,验证码的作用就不多说了,防止机器人程序恶意注册什么的.. 其中User.java,加上了password和cod ...

  4. 草料生成app自动下载的二维码

    草料官网http://cli.im/app 填写iOS和安卓的appid就好了

  5. MySQL(3)-索引

    一.索引类型 在MySQL中,存储引擎使用索引,首先在索引中找到对应值,然后根据匹配的索引记录中找到对应的行. 无论是多么复杂的ORM工具,在精妙和复杂的索引面前都是"浮云".这里 ...

  6. 如何利用 MembershipUser 更改密码

    如何利用 MembershipUser 更改密码 作者: vkvi 来源:千一网络 (原创) 时间: 2009-3-11   完美集成.增强 KindEditor HTML 编辑器 在 ASP.NET ...

  7. mysql的存储引擎如何选择

    myisam:如果表对事务要求不高,用时以查询和添加为主,我们考虑myisam存储,如bbs中的发帖表.回复表 innodb:对事务要求高,保存的数据都是重要的数据,我们建议使用innodb,比如订单 ...

  8. 表单属性问题readonly、disabled、checked,prop的使用

    获取在匹配的元素集中的第一个元素的属性值. 随着一些内置属性的DOM元素或window对象,如果试图将删除该属性,浏览器可能会产生错误.jQuery第一次分配undefined值的属性,而忽略了浏览器 ...

  9. MySQL DATE_FORMAT

    MySQL   DATE_FORMAT(date,format) 根据format字符串格式化date值 (在format字符串中可用标志符: %M 月名字(January……December) %W ...

  10. iOS中的项目新特性页面的处理

    一般项目中都会出现新特性页面,比如第一次使用应用的时候,或者在应用设置里查看新特性的时候会出现. 这里,选择新建一个专门处理项目新特性的控制器,来完成功能. 首先是 NewFeaturesViewCo ...