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. mysql密码遗忘和登陆报错问题

    mysql登录密码忘记,其实解决办法很简单,只需要在mysql的主配置文件my.cnf里添加一行"跳过授权表"的参数选择即可! 在my.cnf中添加下面一行:[root@test- ...

  2. 产品需求文档(PRD)的写作方法之笔记一

    1.写前准备(思维导图): http://www.woshipm.com/?p=80070 1.在写之前,请先很区分清楚什么是MRD文档(市场需求文档),BRD文档(商业需求文档),什么是PRD文档( ...

  3. DLL放在指定目录 以及设置dll调用路径

    一.DLL放在指定目录 在编写C# winform程序中,不免一个项目会有多个工程文件,而这些工程文件之间是相互引用的,所以不想将工程的生成结果(exe或者dll)放在当前工程bin目录下的Debug ...

  4. 添加Distributor失败

    上周做了一个case,客户无法为SQL Server instance配置remote distributor. 下面分享一下排查问题的过程,希望对您排查类似的问题所有帮助. 客户的环境中的SQL S ...

  5. SQL 2014新特性- Delayed durability

    ACID 是数据库的基本属性.其中的D是指"持久性":只要事务已经提交,对应的数据修改就会被保存下来,即使出现断电等情况,当系统重启后之前已经提交的数据依然能够反映到数据库中. 那 ...

  6. Linux 进程详解

    Linux内核的七大区间 .进程管理(进程创建,进程的三种状态,进程间的调度,调度算法...) .内存管理(段式管理(Linux所有段都从0开始),页式管理--地址偏移量) .系统调用(C语言库函数的 ...

  7. CSS background-position 问题

    今天在用background-position进行BODY背景图定位的时候发现100% 100%理应定位在右下角,结果却不一致,查了下语法也没问题 结果发现是background-attachment ...

  8. sobel算子

    #1,个人理解 网上查了很多资料,都说sobel算子是用来检测边缘的,分别给了两个方向上的卷积核,然后说明做法,就说这就是sobel算子.对于我个人来说,还有很多不明白的地方,所以理清下思路. #2, ...

  9. Entity Framework6 with Oracle(可实现code first)

    Oracle 与2个月前刚提供对EF6的支持.以前只支持到EF5.EF6有很多有用的功能 值得升级.这里介绍下如何支持Oracle   一.Oracle 对.net支持的一些基础知识了解介绍. 1.早 ...

  10. 数据字典生成工具之旅(3):PowerDesign文件组成结构介绍及操作

    从这篇开始将正式讲解整个重要部分的实现细节,本篇讲解Pdm文件的解析.其实PDM文件就是XML文件,可以用Editplus或者VS打开查看.了解到这一点之后大家就能猜到,可以用解析XML的方式读取PD ...