SRM 624 Building Heights DivI 解读
几乎相同的一标题。欲了解更多请参阅: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 解读的更多相关文章
- topcoder SRM 624 DIV2 BuildingHeightsEasy
从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可 int minimum(int M, vector <int> heights) { sort(heights.begin( ...
- topcoder SRM 624 DIV2 CostOfDancing
排个序,求前k个元素和即可 int minimum(int K, vector <int> danceCost) { sort(danceCost.begin(),danceCost.en ...
- SRM 624 D2L3: GameOfSegments, 博弈论,Sprague–Grundy theorem,Nimber
题目:http://community.topcoder.com/stat?c=problem_statement&pm=13204&rd=15857 这道题目须要用到博弈论中的经典理 ...
- TC250专场
SRM 623 DIV2 1000pt 题意:给出一个最多50*50的矩阵,每个单元可能为'.'.'P'.'A','.'代表空地,你每次操作可以把一个P或者A拿到空地上,求一个最大的含有相同字符的矩形 ...
- 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 ...
- [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 ...
- CF102920L Two Buildings【分治】【决策单调性】
优秀的分治题目.是"2020-2021 ACM-ICPC, Asia Seoul Regional Contest"的一道题. Description There are \(n\ ...
- UESTC 1817 Complete Building the Houses
Complete Building the Houses Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %l ...
- cdoj 04 Complete Building the Houses 暴力
Complete Building the Houses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/# ...
随机推荐
- JVM-如何判断一段数据是真正的数据,还是对象的引用
JVM 判断一段数据到底是数据还是引用类型,首先要看JVM选择用什么方式.通常这个选择会影响到GC的实现. 一.保守式 如果JVM选择不记录任何这种类型的数据,那么它就无法区分内存里某个位置上的数据到 ...
- 【转】java--final
1.final数据 许多程序设计语言都有自己的办法告诉编译器某个数据是“常数”.常数主要应用于下述两个方面: (1) 编译期常数,它永远不会改变 (2) 在运行期初始化的一个值,我们不希望它发生变化 ...
- 操作VCF卡片信息的第三方jar包:ez-vcard
ez-vcard https://github.com/mangstadt/ez-vcard 目前最新的版本已经更新到0.9.8 起初使用该jar包的时候,是0.9.3,当时遇到一个很尴尬的问题, 就 ...
- char s[]字串和char *s字串有什麼区别?
C語言有兩種字串宣告方式char s[]和char *s,兩者有什麼差異呢? Introduction char s[] = "Hello World"; (只是用字符串常量初始化 ...
- 基于visual Studio2013解决C语言竞赛题之0614递归大元素
题目 解决代码及点评 /************************************************************************/ /* 14. 编一个程 ...
- Unity UGUI——遮罩效果(Mask)
Show Mask Graphic
- Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用
Default.aspx 网页界面 <%@ Page Language="C#" AutoE ...
- 基于visual Studio2013解决C语言竞赛题之1015日期计算
题目 解决代码及点评 /* 15. 已知某年不是闰年,给定该年某一天的月份和日期, 求这一天是该年的第几天. */ #include <stdio.h> #incl ...
- [linux]linux命令学习-netstat
linux非常多服务都与网络相关.当服务调不通或者是启动port被占用,或者是又是被防火墙挡住的时候,就须要查询网络相关的问题,netstat命令之前仅仅会用一两个參数这里.好好学习一番. 经常使用的 ...
- 最大似然预计(Maximum likelihood estimation)
一.定义 最大似然预计是一种依据样本来预计模型參数的方法.其思想是,对于已知的样本,如果它服从某种模型,预计模型中未知的參数,使该模型出现这些样本的概率最大.这样就得到了未知參数的预计值. 二 ...