Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心
2017-03-19 20:42
555 查看
题目地址:这里
题意:一个数x,可以变成2x,或者变成2x+1,可以变化若干次。现在给你n个不同的数Y,你需要找到n个不同的x,使得这n个不同的x经过变化之后,能够得到Y数组,你要使得最初的最大值最小。问你应该怎么做。
解法:贪心,每次选择最大的数,然后使得最大数变小即可,能变就变,用一个set去维护就好了。
题意:一个数x,可以变成2x,或者变成2x+1,可以变化若干次。现在给你n个不同的数Y,你需要找到n个不同的x,使得这n个不同的x经过变化之后,能够得到Y数组,你要使得最初的最大值最小。问你应该怎么做。
解法:贪心,每次选择最大的数,然后使得最大数变小即可,能变就变,用一个set去维护就好了。
//CF 722D #include <bits/stdc++.h> using namespace std; set <int> s; int n; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++){ int x; scanf("%d", &x); s.insert(-x); } while(1){ int x = -*s.begin(); int k = *s.begin(); x /= 2; while(x){ if(s.find(-x) == s.end()){ s.insert(-x); break; } x/=2; } if(x == 0){ for(auto it : s){ cout << -it << " "; } cout << endl; return 0; } s.erase(k); } }
相关文章推荐
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心+优先队列
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)D. Generating Sets(贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- D. Generating Sets(贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- A. Broken Clock (贪心)
- 【Intel Code Challenge Elimination Round (Div1 + Div2, combined) D】【贪心 暴力 SET】Generating Sets n个不同的x变
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets __ dfs+优先队列+贪心
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) [D] Destroying Array
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)E. Research Rover (容斥Lucas)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array -- 逆向思维
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)F. Cyclic Cipher
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array 带权并查集
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- C. Destroying Array (并查集)
- Codeforces Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) 部分题解
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- B. Verse Pattern(水题)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) E
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)C. Destroying Array(想法题/并查集)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array(并查集)