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/# ...
随机推荐
- ArrayList集合--C#
static void Main(string[] args) { //实例化出一个集合对象 ArrayList list = new ArrayList(); /*添加*/ //--添加单个元素 l ...
- SAX方式解析XML
sax解析分为以下几步: 1 获取一个saxparserfactory 2 获取一个解析器 3 创建handler对象,这个myHandler是继承了DefaultHandler的一个类,这个实现类里 ...
- 一个开发原则:永远不要返回NULL
看一篇文章:10个经典的java开发原则,里面一个原则:永远不要返回NULL. 说实在的,我对这个原则体会不是很深,平时在使用对象前,检查是否为null已经成了习惯,也是我要求开发人员的一个标准动作. ...
- java Native 方法
一. 什么是Native Method 简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个java的方法:该方法的实现由非j ...
- windows api 梳理
PathMatchSpec Function Searches a string using a Microsoft MS-DOS wild card match type. Syntax BOOL ...
- Microsoft Visual Studio International Pack 1.0 SR1--关于汉字转拼音
Microsoft Visual Studio International Pack 1.0 SR1————微软的一个类库 地址:http://www.microsoft.com/zh-cn/down ...
- 【linux】内核make编译链接相关变量定义
欢迎转载,转载时请保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:http:// ...
- (原创)优酷androidclient 下载中 bug 解决
在网络情况不好的情况下,优酷androidclient下载视频会终止,用户放弃下载点击 删除该任务以后,切换到网络好的情况下进行下载,会显示该视频已在下载队列里,然后clientUI界面却什么都看不到 ...
- 怎样查看apk须要支持的Android版本号
假设有一个apk,须要知道他最低安装支持的Android版本号是什么,应该怎样查看呢? 直接将apk后缀名改为rar或者zip,拉出AndroidManifest.xml?不行,AndroidMani ...
- C#用链式方法
C#用链式方法表达循环嵌套 情节故事得有情节,不喜欢情节的朋友可看第1版代码,然后直接跳至“三.想要链式写法” 一.起缘 故事缘于一位朋友的一道题: 朋友四人玩LOL游戏.第一局,分别选择位置:中 ...