TopCoder SRM 596 DIV 1 250
2016-12-03 19:54
513 查看
Problem Statement | ||||||||||||
You have an array with N elements. Initially, each element is 0. You can perform the following operations: Increment operation: Choose one element of the array and increment the value by one. Doubling operation: Double the value of each element. You are given a vector <int> desiredArray containing N elements. Compute and return the smallest possible number of operations needed to change the array from all zeros to desiredArray. | ||||||||||||
Definition | ||||||||||||
| ||||||||||||
Limits | ||||||||||||
| ||||||||||||
Constraints | ||||||||||||
- | desiredArray will contain between 1 and 50 elements, inclusive. | |||||||||||
- | Each element of desiredArray will be between 0 and 1,000, inclusive. | |||||||||||
Examples | ||||||||||||
0) | ||||||||||||
| ||||||||||||
1) | ||||||||||||
| ||||||||||||
2) | ||||||||||||
| ||||||||||||
3) | ||||||||||||
| ||||||||||||
4) | ||||||||||||
| ||||||||||||
5) | ||||||||||||
|
集训队题解
给出一个序列,n个元素,初始为0。操作有二:
1.给某个数加1
2.给所有数乘2
求变成目标序列的最小次数。
#include <bits/stdc++.h> using namespace std; class IncrementAndDoubling { public: int getMin(vector<int> desiredArray) { int cnt = 0, maxi = 0; for (auto i : desiredArray) for (int j = 0; i >> j; ++j) maxi = max(maxi, j), cnt += (i >> j) & 1; return cnt + maxi; } };
@Author: YouSiki
相关文章推荐
- TopCoder 250 points 12-SRM 149 DIV 2 103.92/250 41.57%
- TopCoder SRM 612 DIV1 250 EmoticonsDiv1
- topcoder srm 610 div2 250
- TopCoder SRM 667 Div1 Problem 250 - OrderOfOperations (状压dp)
- TopCoder 250 points 17-SRM 152 DIV 1 106.51/250 42.60%
- 【topcoder SRM 652 DIV2 250】ValueOfString
- Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索
- TopCoder 250 points 13-SRM 150 DIV 1 82.63/250 33.05%
- TopCoder 250 points 18-SRM 152 DIV 2 167.05/250 66.82%
- TopCoder 250 points 28-SRM 157 DIV 2 185.60/250 74.24%
- TopCoder_SRM_144_DIV2_250_Time
- 小朋友学TopCoder(7):SRM726 DIV2 250-point
- TopCoder 250 points 3-SRM 145 DIV 1 84.71/250 33.88%
- TopCoder 250 points 19-SRM 153 DIV 1 84.72/250 33.89%
- TopCoder 250 points 4-SRM 145 DIV 2 128.72/250 51.49%
- TopCoder 250 points 20-SRM 153 DIV 2 216.58/250 86.63%
- 【topcoder SRM 702 DIV 2 250】TestTaking
- topcoder SRM 548 DIV2 250
- Topcoder SRM 661 (Div.1) 250 MissingLCM - 数论
- topcoder SRM 637 div2+div1 250