几乎相同的一标题。欲了解更多请参阅: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. Struct初学的,页面跳转

    Filter控制器 jsp页面代码 <form action="page_login.action" method="post">     user ...

  2. C# 客户端服务端的编写

    客户端的代码 class client { public void mehod() { TcpClient tcp = new TcpClient(); tcp.Connect(IPAddress.P ...

  3. 原生app与web app的比较

    http://www.2ee9.com/news/news_show_36_237.html http://zhidao.baidu.com/link?url=7lWq2tgqiMiDmsRd54hO ...

  4. Linux解压乱码

    .向系统添加windows下的字符编码: sudo vim /var/lib/locales/supported.d/local 添加一下编码: zh_CN.GBK GBK zh_CN.GB2312 ...

  5. Tomcat与web程序结构与Http协议

    telnet 一:打开telnet服务: 控制面板------> 程序和功能---> 打开或关闭windows功能---> 选中 Telnet客户端--->确定 二:测试tel ...

  6. JavaScript对滚动栏的操作

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  7. Android 富文本框实现 RichEditText

    Android系统自带控件没有富文本框控件,如果想写一封带格式的邮件基本上不可能,EdtiText只有默认一种格式,显示不能滿足要求,!!正好项目需要研究了一下,开发了此控件,现将一些源代码开放一下, ...

  8. Android如何监听蓝牙耳机的按键事件

    写在前面: 直接想要代码很简单,你直接把滚动条拉到最底端就可以看到.如果想要十分地了解为什么,那就按照我规划的一步一步来理解.以下测试环境以手头上有的「Bluedio + 红米手机」. 1.蓝牙耳机的 ...

  9. 基于visual Studio2013解决面试题之1101差值最小

     题目

  10. 操作3 mongodb和mysql 开启慢查询日志 ,以及mongodb从配置文件启动

    1. mongodb从配置文件启动 创建配置文件:/usr/local/mongodb/etc/mongodb.conf 配置文件的内容为: #Directory and relavent set d ...