SRM 624 Building Heights DivI 解读
2015-08-07 12:33
483 查看
几乎相同的一标题。欲了解更多请参阅:http://community.topcoder.com/stat?c=problem_statement&pm=13211&rd=15857
思维:
1 序列
2 大厦的当前数量的计算i时候,全部可能的最小建筑物改动数
3 每次计算i+1的时候。全部可能的最小建筑物改动数
4 同一时候能够比較得到i+1的时候最小改动数
得到的程序也不复杂
思维:
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; } };
相关文章推荐
- [Leetcode]Implement Queue using Stacks
- MAC上配置搭配CH340/CH341 USB转串口芯片的Arduino
- 理解 Android Build 系统
- C#多线程以及更新UI
- Nopcommerce kendo UI Roxy Fileman控件的汉化
- editui界面常用代码
- STL之priority_queue
- SWT中的UI线程
- Vagrant is attempting to interface with the UI in a way that requires a TTY
- 再说bluetooth4.2
- Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the desi
- StringBuffer与StringBuilder 区别
- Jsp的request
- UVALive 5881 Unique Encryption Keys
- js生成UUID
- setValue: forKeyPath:
- 浅谈:UEO就是SEO的一种
- Android 重写系统控件UI,自定义进度条
- 超详细!iOS 并发编程之 Operation Queues
- druid连接无法回收...