SRM 624 Building Heights DivI 题解
2014-06-22 09:30
204 查看
和前面的题目差不多,具体看: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; } };
相关文章推荐
- SRM 624 Building Heights DivI 解读
- topcoder SRM 624 DIV2 BuildingHeightsEasy
- SRM 624 D2L3: GameOfSegments, 博弈论,Sprague–Grundy theorem,Nimber
- SRM 622 D1L1: BuildingRoutes,shortest path
- SRM 624 D2L3: GameOfSegments, 博弈论,Sprague–Grundy theorem,Nimber
- topcoder SRM 624 DIV2 CostOfDancing
- SRM 624 D1L2:DrivingPlans,求解所有的最短路径
- Topcoder SRM 636 Div2 C
- 使用自定义图标的MFC工程因原图标文件丢失无法building的解决办法
- SRM659 1100pts
- UVA624 - CD (DFS)
- Could not connect to SMTP host,PKIX path building failed,unable to find valid certification path...
- Building a RESTful Web Service
- SRM-697-DIV2
- PKIX path building failed
- AndroidStudio导入项目一直卡在Building gradle project info
- SRM 510 DIV2 1000 TheLuckyBasesDivTwo
- HDU 5033 Building (单调栈维护凸包)
- Android Studio导入项目非常慢——卡在Building '项目名' Gradle project info