标签:算法
http://www.lintcode.com/en/problem/wood-cut/#
二分答案,贪心验证,具有单调性
class Solution { public: /** *@param L: Given n pieces of wood with length L[i] *@param k: An integer *return: The maximum length of the small pieces. */ int woodCut(vector<int> L, int k){ if(L.empty()) return 0; LL low=0, high=*max_element(L.begin(), L.end()); while(low<high){ if(low+1==high){ LL ans=0; for(auto e: L){ ans+=e/high; } if(ans>=k) return high; else return low; } LL mid=(low+high)/2; LL ans=0; for(auto e: L){ ans+=e/mid; } if(ans>=k) low=mid; else high=mid-1; } return low; } }S;
introsort C++ STL 没有最坏情况
timsort msort isort 综合
dual pivot qsort JDK7 arrays.sort 里面采用 任然有最坏n^2情况
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:算法
原文地址:http://blog.csdn.net/richardzrc/article/details/46780055