几乎相同的一标题。欲了解更多请参阅:http://community.topcoder.com/stat?c=problem_statement&pm=13211&rd=15857

思维:

1 序列

2 大厦的当前数量的计算i时候,全部可能的最小建筑物改动数

3 每次计算i+1的时候。全部可能的最小建筑物改动数

4 同一时候能够比較得到i+1的时候最小改动数

得到的程序也不复杂

#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std; class BuildingHeights
{
public:
int minimum(vector<int> heights)
{
int n = (int)heights.size();
sort(heights.begin(), heights.end());
vector<int> cost(n, 0); int ans = 0;
for (int i = 0; i < n-1; i++)
{
int c = INT_MAX;
for (int j = n-1; j > i; j--)
{
cost[j] = cost[j-1] + (heights[j]-heights[j-1])*(i+1);
c = min(c, cost[j]);
}
ans ^= c;
}
return ans;
}
};

版权声明:笔者心脏靖,景空间地址:http://blog.csdn.net/kenden23/,可能不会在未经作者同意转载。

SRM 624 Building Heights DivI 解读的更多相关文章

  1. topcoder SRM 624 DIV2 BuildingHeightsEasy

    从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可 int minimum(int M, vector <int> heights) { sort(heights.begin( ...

  2. topcoder SRM 624 DIV2 CostOfDancing

    排个序,求前k个元素和即可 int minimum(int K, vector <int> danceCost) { sort(danceCost.begin(),danceCost.en ...

  3. SRM 624 D2L3: GameOfSegments, 博弈论,Sprague–Grundy theorem,Nimber

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=13204&rd=15857 这道题目须要用到博弈论中的经典理 ...

  4. TC250专场

    SRM 623 DIV2 1000pt 题意:给出一个最多50*50的矩阵,每个单元可能为'.'.'P'.'A','.'代表空地,你每次操作可以把一个P或者A拿到空地上,求一个最大的含有相同字符的矩形 ...

  5. 218. The Skyline Problem *HARD* -- 矩形重叠

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  6. [Swift]LeetCode218. 天际线问题 | The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  7. CF102920L Two Buildings【分治】【决策单调性】

    优秀的分治题目.是"2020-2021 ACM-ICPC, Asia Seoul Regional Contest"的一道题. Description There are \(n\ ...

  8. UESTC 1817 Complete Building the Houses

    Complete Building the Houses Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %l ...

  9. cdoj 04 Complete Building the Houses 暴力

    Complete Building the Houses Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/# ...

随机推荐

  1. vs2016 创建 vsto excel 文件项目的一个问题

    新工作需要些一个基于Excel开发一个工具,vs的 vsto 功能很好用,封装了基于开发office 开的一些工具.但是在实际使用时,创建项目总是报错,提示打开excel文件失败.项目是需要创建一个e ...

  2. java--匿名类

    匿名类的使用 package Test; abstract class C525{ abstract void foo(); } class B525{ // 局部类只能访问外包方法中的final成员 ...

  3. C语言中Const与指针(转载)

    一.说明指针常量.指向常量的指针和指向常量的常量指针的含义.区别和共同点 首先,以上三种概念的共同点:都指的是指针 指针也是一种变量,它存储指定类型的变量的内存地址,如char* 来声明一个字符型指针 ...

  4. ORACLE客户端乱码

    sqlplus 打开CMD窗口,出现乱码情况的解决办法 C:\Documents and Settings>set NLS_LANG=american_america.AL32UTF8 C:\D ...

  5. cocos2d-x游戏开发系列教程-坦克大战游戏之子弹和地图碰撞

    上篇文章实现了坦克与地图碰撞的检测, 这篇我们继续完成子弹和地图的碰撞检测. 1.先设计一个子弹类Bullet,如下所示: class Bullet : public CCSprite { publi ...

  6. ajaxSubmit提交文件表单不执行success

    先描述一下我遇到的问题,系统里所有的表单都用ajaxSubmit来提交,成功回调success函数,普通表单都是没有问题的,但是有文件上传的表单就不行了,不会回调success,经验证会回调compl ...

  7. perl use base 代替 @ISA

    packge Mule; use base ("Horse", "donkey"); # 声明一个超类 它是下面东西的缩写: package Mule; BEG ...

  8. 基于visual Studio2013解决面试题之1007鸡蛋和篮子

     题目

  9. 基于visual Studio2013解决面试题之0907大数乘法

     题目

  10. [置顶] Java 8全面解析!不知道的来看看那!

    java8的面世惊动了不少业界人员,让我们一起来看看吧! 函数式接口 函数式接口是只定义了一个抽象方法的接口.Java 8引入了FunctionalInterface注解来表明一个接口打算成为一个函数 ...