几乎相同的一标题。欲了解更多请参阅: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. JQuery - 改变css样式

    jQuery提供css()的方法来实现嵌入式改变元素样式,css()方法在使用上具有多样性.其中一种接受两个输入参数:样式属性和样式值,它们之间用逗号分开.比如我们要改变链接颜色,我们可以使用下面的代 ...

  2. 3522: [Poi2014]Hotel( 树形dp )

    枚举中点x( 即选出的三个点 a , b , c 满足 dist( x , a ) = dist( x , b ) = dist( x , c ) ) , 然后以 x 为 root 做 dfs , 显 ...

  3. Qt学习之路(24): QPainter(改写paintEvent)

    多些大家对我的支持啊!有朋友也提出,前面的几节有关event的教程缺少例子.因为event比较难做例子,也就没有去写,只是把大概写了一下.今天带来的是新的部分,有关Qt的2D绘图.这部分不像前面的内容 ...

  4. C# char[]与string之间的相互转换

    string 兑换 Char[] string ss = "abcdefg"; char[] cc = ss.ToCharArray(); Char[] 转换成string str ...

  5. UVA 10581 - Partitioning for fun and profit(数论递推)

    10581 - Partitioning for fun and profit 题目链接 题意:给定m, n,表示分配给n个格子,分配m个数字进去,每一个格子最少1,而且序列要是递增的,问第k个字典序 ...

  6. Android 应用程序签名

    本文主要介绍Android应用程序签名的相关理论知识以及怎样公布Android应用程序. 1.签名的概念 为大家所熟知的日常生活中的签名,它是代表某个人的特殊标记,用于唯一标识某个人.而Android ...

  7. MFC 只启动一个程序实例

    问题描述: 我们开发过程中可能会经常遇到,只启动一个程序实例.即一个程序启动之后,如果再次执行该程序,将会恢复之前打开的程序,而不是打开一个新的程序. 实现原理:利用FindWindow/FindWi ...

  8. C++ 库研究笔记——通过inline避免hpp 的mutiple definition 错误

    C++用了这么多年,这个却第一次知道,以前没用过hpp 这样: // foo.hpp void foo() { /* body */ } // a.cpp #include "foo.hpp ...

  9. WSGI详解

    WSGI接口 了解了HTTP协议和HTML文档,我们其实就明白了一个Web应用的本质就是: 浏览器发送一个HTTP请求: 服务器收到请求,生成一个HTML文档: 服务器把HTML文档作为HTTP响应的 ...

  10. 调用ShellExecute所须要头文件

    调用ShellExecute所须要头文件 #include   "windows.h " #include   "shellapi.h "