二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C
http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- mac安装软件系列
1,mac安装homebrew,注意不能用root权限安装 #ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew ...
- 关于Webapp的注意事项
meta标签 <meta name="viewport" content="width=device-width, initial-scale=1.0, user- ...
- Storm-0.9.0.1安装部署 指导
可以带着下面问题来阅读本文章: 1.Storm只支持什么传输 2.通过什么配置,可以更改Zookeeper默认端口 3.Storm UI必须和Storm Nimbus部署在同一台机器上,UI无法正常工 ...
- Spring Security(03)——核心类简介
目录 1.1 Authentication 1.2 SecurityContextHolder 1.3 AuthenticationManager和Authentication ...
- apache动态添加模块
Apache已经安装完毕并投入运行,但是后来却发现部分模块没有加载,当然有两个方法: 1. 一是完全重新编译Apache, 再安装 2. 编译模块为SO文件,使用LoadModule指令加载扩展模块. ...
- Linux入门(三)搭建服务器linux运行环境LAMP/LNMP
本文内容主要根据慕课网教学视频整理,原链接http://www.imooc.com/learn/170 我用的linux系统是ubuntu 12.04 LTS 虚拟机是VMware Workstat ...
- HDU 2058 The sum problem(枚举)
The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the ...
- 【Linux】zookeeper构造伪集群
1.在一台机器装安装3个zk server,构建伪集群模式安装步骤如下:1.下载zookeeper,下载地址:http://mirror.bit.edu.cn/apache/zookeeper/zoo ...
- MFC下MCI的使用播放音乐
最近研究了一下MFC下的音乐的播放,主要使用了MCI 1.需要包含的库文件 在链接资源里(link)添加库文件VFW32.lib winmm.lib 2.包含的头文件 #include <mms ...
- phabricator 搭建
os:debian7 Installation Guide :https://secure.phabricator.com/book/phabricator/ $ cd /data # 安装目录 da ...