首页 > 其他 > 详细

topcoder SRM 624 DIV2 BuildingHeightsEasy

时间:2014-06-15 21:47:47      阅读:374      评论:0      收藏:0      [点我收藏+]

从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可

    int minimum(int M, vector <int> heights)
    {
        sort(heights.begin(),heights.end());
        int minFloor = 10000;
        for(int i = heights.size()-1; i >=M-1; -- i){
            int floor = 0;
            for(int j = 0; j < M; ++j) floor +=heights[i]-heights[i-j];
            minFloor =min(minFloor,floor);
        }
        return minFloor;
    }

  

topcoder SRM 624 DIV2 BuildingHeightsEasy,布布扣,bubuko.com

topcoder SRM 624 DIV2 BuildingHeightsEasy

原文:http://www.cnblogs.com/xiongqiangcs/p/3785461.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!