poj-1064Cable master(二分)
生活随笔
收集整理的這篇文章主要介紹了
poj-1064Cable master(二分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:
給你一些纜線,把這些纜線分成等長的m段,長度盡量大(c++過)
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int n,k; double a[10005]; bool greedy(double x) {int count = 0;for(int i = 0;i < n;i++){int ret = a[i]/x;count += ret;if(count >= k) return true;}return false; } void search(double l,double r) {while(r - l > 1e-6){double mid = ( l + r )/2;if(greedy(mid)) l = mid;else r = mid;}r = r*100;int ans = r;printf("%.2lf\n",ans*0.01); } int main() {while(~scanf("%d%d",&n,&k)){double max = 0;for(int i = 0;i < n;i++){scanf("%lf",&a[i]);if(max < a[i]) max = a[i];} search(0,max);} }
總結
以上是生活随笔為你收集整理的poj-1064Cable master(二分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: poj-2101Honey and Mi
- 下一篇: JeecgBoot 单表数据导出多she