• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

HDU-1969 Pie

题意:有F+1个人,N块半径为ri[i](i=1,2...N)的馅饼,使每个人得到相同面积的一部分馅饼,问馅饼的最大面积是多少。

思路:因为每个人得到的最大面积只能是所有馅饼的面积和sum/(F+1),所以二分枚举0到sum/(F+1)。因为精度问题w了好多次...

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969

 

View Code
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <string>
 7 using namespace std;
 8 #define Pi acos(-1.0)
 9 #define MAXN 10005
10 #define eps 1e-6
11 
12 int N,F,t;
13 double sum,ri[MAXN];
14 
15 int main(){
16     scanf("%d",&t);
17     while(t--){
18         scanf("%d%d",&N,&F);
19         sum=0;
20         double val;
21         for(int i=1;i<=N;i++){
22             scanf("%lf",&val);
23             ri[i]=Pi*val*val;
24             sum+=ri[i];
25         }
26         F++;
27         double l=0.0,r=sum/F,res;
28         while(r-l>eps){
29             double mid=(l+r)/2;
30             int cnt=0;
31             for(int i=1;i<=N;i++){
32                 cnt+=(int)(ri[i]/mid);
33             }
34             if(cnt>=F){l=mid; res=mid;}
35             else r=mid;
36         }
37         printf("%.4lf\n",res);
38     }
39     return 0;
40 }
posted @ 2012-10-25 08:53  Hug_Sea  阅读(121)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3