码迷,mamicode.com
首页 > 其他好文 > 详细

uva 12097(二分)

时间:2017-08-25 13:43:00      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:cstring   algorithm   using   name   log   include   style   ring   str   

就是二分

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const double pi=acos(-1.0);
const int maxn=10000+100;
int t,n,f;
double a[maxn];
const double esp=1e-5;
bool is_ok(double ss)
{
    int ans=0;
    for(int i=1;i<=n;i++)
      ans+=floor(a[i]/ss);
    if(ans<f+1) return 1;
    else return 0;
}
int main()
{
   scanf("%d",&t);
   while(t--)
   {
       scanf("%d%d",&n,&f);
       double r,maxi=0;
       for(int i=1;i<=n;i++)
       {
           scanf("%lf",&r);
            a[i]=pi*r*r;
          maxi=max(maxi,a[i]);
       }
       double l=0;
       r=maxi;
       while(r-l>esp)
       {
             double mid=(l+r)/2.0;
          if(is_ok(mid)) r=mid;
          else l=mid;
       }
       printf("%.4lf\n",l);
   }
    return 0;
}

 

uva 12097(二分)

标签:cstring   algorithm   using   name   log   include   style   ring   str   

原文地址:http://www.cnblogs.com/Wangwanxiang/p/7427288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!