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

    
Class: IncrementAndDoubling
Method: getMin
Parameters: vector <int>
Returns: int
Method signature: int getMin(vector <int> desiredArray)
(be sure your method is public)

Limits

    
Time limit (s): 2.000
Memory limit (MB): 64

Constraints

- desiredArray will contain between 1 and 50 elements, inclusive.
- Each element of desiredArray will be between 0 and 1,000, inclusive.

Examples

0)  
    
{2, 1}
Returns: 3
One of the optimal solutions is to apply increment operations to element 0 twice and then to element 1 once. Total number of operations is 3.
1)  
    
{16, 16, 16}
Returns: 7
The optimum solution looks as follows. First, apply an increment operation to each element. Then apply the doubling operation four times. Total number of operations is 3+4=7.
2)  
    
{100}
Returns: 9
 
3)  
    
{0, 0, 1, 0, 1}
Returns: 2
Some elements in desiredArray may be zeros.
4)  
    
{123, 234, 345, 456, 567, 789}
Returns: 40
 
5)  
    
{7,5,8,1,8,6,6,5,3,5,5,2,8,9,9,4,6,9,4,4,1,9,9,2,8,4,7,4,8,8,6,3,9,4,3,4,5,1,9,8,3,8,3,7,9,3,8,4,4,7}
Returns: 84
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

集训队题解

给出一个序列,n个元素,初始为0。操作有二:

1.给某个数加1

2.给所有数乘2

求变成目标序列的最小次数。

 #include <bits/stdc++.h>
using namespace std; class IncrementAndDoubling {
public:
int getMin(vector<int> desiredArray) {
int cnt = , maxi = ;
for (auto i : desiredArray)
for (int j = ; i >> j; ++j)
maxi = max(maxi, j), cnt += (i >> j) & ;
return cnt + maxi;
}
};

@Author: YouSiki

TopCoder SRM 596 DIV 1 250的更多相关文章

  1. Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索

    最近连续三次TC爆零了,,,我的心好痛. 不知怎么想的,这题把题意理解成,第一次选择j,第二次选择i后,只能从1~i-1.i+1~j找,其实还可以从j+1~n中找,只要没有被选中过就行... [题意] ...

  2. 【topcoder SRM 702 DIV 2 250】TestTaking

    Problem Statement Recently, Alice had to take a test. The test consisted of a sequence of true/false ...

  3. Topcoder SRM 661 (Div.1) 250 MissingLCM - 数论

    [题意] 给你一个数N(1<=N<=10^6),要求最小的M(M>N),使得lcm(n+1,n+2,...m)=lcm(1,2,3,...,m) [思路] 手速太慢啦,等敲完代码的时 ...

  4. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  5. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  6. 竞赛图的得分序列 (SRM 717 div 1 250)

    SRM 717 DIV 1 中 出了这样一道题: 竞赛图就是把一个无向完全图的边定向后得到的有向图,得分序列就是每个点的出度构成的序列. 给出一个合法的竞赛图出度序列, 要求构造出原图(原题是求(u, ...

  7. [topcoder]SRM 646 DIV 2

    第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...

  8. [topcoder]SRM 633 DIV 2

    第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...

  9. SRM 596 DIV 2

    前段时间终于配置好了TopCoder的环境,所以就拿这场的DIV2练习了一下 1. 250pt FoxAndSightseeing 题意 给你n个城市的位置,他们在同一直线上,要求你跳过其中某一个城市 ...

随机推荐

  1. NPM 如何升级?

  2. Web Api其中的PUT功能演示

    Insus.NET这几天均在学习Web API知识,并练习.怎样获取数据,提交数据或是保存数据.你可以温习一下<Post model至Web Api创建或是保存数据>http://www. ...

  3. ASP.NET性能优化之减少请求

    在上篇<ASP.NET性能优化之让浏览器缓存动态网页> 中的方案中,浏览器发送If-Modified-Since将是否需要使用自己的缓存交给WEB服务器去决定,服务器告知浏览器去读缓存,浏 ...

  4. 数据库 SQL语法二

    聚合函数 -SUM([DISTINCT] FIELDNAME) 求指定列之和,[DISTINCT]选项表示剔除重复记录 例如:SELECT SUM(age) FROM TABLE1; SELECT S ...

  5. ASP.NET XmlSerializer权限问题

    今天碰到一个奇怪问题.因为在2台服务器上做文件共享,使服务器A能访问服务器B的共享目录.在IIS上使用虚拟目录实现的话,需要给应用程序池指定一个统一的账号.在调试的时候能够使用,但是一部署到服务器上, ...

  6. 学习SQLite之路(五) C/C++ SQLite开发实例

    介绍一种乌班图中使用sqlite的用法,非常简单,下面的例子是在乌班图12.04中实现的: 1,先安装两个东西: sudo apt-get install sqlite sqlite3 sudo ap ...

  7. 学习SQLite之路(四)

    20160621 更新 参考: http://www.runoob.com/sqlite/sqlite-tutorial.html 1. SQLite   alter命令:不通过执行一个完整的转储和数 ...

  8. SQLite常用点滴总结(转)

    expressionexpr ::=     expr binary-op expr |expr [NOT] like-op expr [ESCAPE expr] |unary-op expr |( ...

  9. MATLAB中plot()画图的颜色线型和希腊字母参数设置

    y         黄色           ·             点线      m         粉红           ○             圈线      c          ...

  10. Matlab中数组元素引用——三种方法

    Matlab中数组元素引用——三种方法   1.Matlab中数组元素引用有三种方法 1 2 3 1.下标法(subscripts) 2.索引法(index) 3.布尔法(Boolean) 注意:在使 ...