poj 1064 Cable master
生活随笔
收集整理的這篇文章主要介紹了
poj 1064 Cable master
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給n段繩子,長度分別為c1,c2.....,切成相等的k段,求最大的長度
分析:二分長度,唯一注意的一點,輸出的時候的精度
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; const int maxn=1e4+5; const double esp=1e-9; double c[maxn]; int n,k;bool judge(double mid){int cnt=0;for(int i=0;i<n;i++)cnt+=(int)(c[i]/mid);return cnt>=k; }int main(){while(~scanf("%d%d",&n,&k)){double l=0,r=0;for(int i=0;i<n;i++){scanf("%lf",c+i);r+=c[i];}r/=k;while(r-l>esp){double mid=(l+r)/2;if(judge(mid))l=mid;elser=mid;}r=floor(r*100)/100;printf("%.2f\n",r);}return 0; } View Code?
轉載于:https://www.cnblogs.com/jihe/p/5571278.html
總結
以上是生活随笔為你收集整理的poj 1064 Cable master的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SU Demos-02Filtering
- 下一篇: iOS开发学习之MapKit - 获得在