几乎相同的一标题。欲了解更多请参阅: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. Steve Yegge:Google面试秘籍

    我憋了很长时间想写点关于去Google面试的秘籍.不过我总是推迟,因为写出来的东西会让你抓狂.很可能是这样.如果按统计规律来定义"你"的话,这文章很可能让你不爽. 为啥呢?因为啊- ...

  2. 【转】文件恢复神器extundelete

    参考博文: 1.Linux中VMware虚拟机增加磁盘空间的扩容操作 http://www.net130.com/CMS/Pub/special/special_virtual/special_vir ...

  3. [转]tripwire-文件指纹

    原文链接:http://www.ipython.me/centos/tripwire-file-md5.html Tripwire是目前最为著名的unix下文件系统完整性检查的软件工具,这一软件采用的 ...

  4. android switch语句case expressions must be constant expressions

    在项目中遇到这样的Exception:case expressions must be constant expressions public class StandingCityActivity e ...

  5. SQLite数据库框架ORMLite与GreenDao的简单比较

    笔记摘要:最近准备使用数据库做个缓存,以前因为项目中的实时性要求比较高,所以在整体的框架中就没有加缓存,有些地方只 是简单的将对象保存到了Preference中,所以并没有对数据库方面有所研究,既然准 ...

  6. C++和JNI的数据转换

    链接地址:http://blog.csdn.net/manymore13/article/details/19078713 转载地址:http://www.cnblogs.com/daniel-she ...

  7. BZOJ 3585: mex( 离线 + 线段树 )

    离线, 询问排序. 先处理出1~i的答案, 这样可以回答左端点为1的询问.完成后就用seq(1)将1到它下一次出现的位置前更新. 不断这样转移就OK了 ------------------------ ...

  8. [置顶] cocos2d-x 3.0游戏开发xcode5帅印博客教学 003.[HoldTail]游戏世界以及背景画面

    cocos2d-x 3.0游戏开发xcode5帅印博客教学 003.[HoldTail]游戏世界以及背景画面 写给大家的前言,在学习cocos2d-x的时候自己走了很多的弯路,也遇到了很多很多问题,不 ...

  9. Ch02 从零开始实例学习5

    演练:添加模型 原文链接:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-model ...

  10. hdu 3998 (dp+最大流)

    题意:求最长上升子序列的长度和数量. 分析:用dp求出最长上升子序列m,dp数组存的就是该元素为子序列结尾的长度,源点与长度为1的点建边,长度为m的与汇点连边,然后枚举任意两个元素,ai,aj(ai& ...