SRM 624 Building Heights DivI 解读
生活随笔
收集整理的這篇文章主要介紹了
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/,可能不會在未經作者同意轉載。
轉載于:https://www.cnblogs.com/hrhguanli/p/4710401.html
總結
以上是生活随笔為你收集整理的SRM 624 Building Heights DivI 解读的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拒绝996,像Phodal一样天天秀恩爱
- 下一篇: 截图即OCR识别文字天若开源使用