zoukankan      html  css  js  c++  java
  • HDU 1969 (二分)

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

    Pie

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4547    Accepted Submission(s): 1837

    Problem Description
    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.
    My friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size.
    What is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.
     
    Input
    One line with a positive integer: the number of test cases. Then for each test case:
    ---One line with two integers N and F with 1 <= N, F <= 10 000: the number of pies and the number of friends.
    ---One line with N integers ri with 1 <= ri <= 10 000: the radii of the pies.
     
    Output
    For each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10^(-3).
     
    Sample Input
    3
    3 3
    4 3 3
    1 24
    5
    10 5
    1 4 2 3 4 5 6 5 4 2
     
    Sample Output
    25.1327
    3.1416
    50.2655
     
    题目大意:N块饼,F个朋友,还有自己;每个人分得一块相同分量的饼,不能由几小块凑成,求能分成的最大体积/面积。
    分析:精度要求高,pi要用反余弦pi=acos(-1.0);
     
     1 #include <cstdio>
     2 #include <cmath>
     3 #include <iostream>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 double pi = acos(-1.0);
     8 int N,F,t;
     9 double v[11111];
    10 
    11 int main()
    12 {
    13     int T;
    14     int N,F;
    15     int i;
    16     int r;
    17     double left,right,mid;
    18     double v[10011];
    19 
    20 
    21     scanf("%d",&T);
    22     while(T--)
    23     {
    24         scanf("%d%d",&N,&F);
    25         F++;//加上自己
    26         right = 0;
    27         for(i=0; i<N; i++)
    28         {
    29             scanf("%d",&r);
    30             v[i] = pi * r * r;
    31             right = max(right, v[i]);//找出面积最大的饼,为二分上界
    32         }
    33         left=0;
    34         mid=(left + right) / 2;
    35         while(right - left >= 0.0000001)//精度要求
    36         {
    37             t=0;
    38             for(i=0; i<N; i++) t += (int)(v[i]/mid);
    39             if(t >= F)
    40             left = mid;
    41             else
    42             right = mid;
    43             mid = (left + right) / 2;
    44         }
    45         printf("%0.4lf
    ",mid);
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    二叉树 排序二叉树-可以通过中序遍历得到排序的数据 二叉排序树时间复杂度O(logn),
    双链表排序
    Linux C 单链表 读取文件 并排序 实例并解释
    Linux 中文乱码问题
    双向链表排序
    玩转iOS开发
    Firefox OS简单介绍
    深入理解Dalvik虚拟机- 解释器的执行机制
    菜鸟学Struts——I18N对国际化的支持
    【leetcode】Flatten Binary Tree to Linked List
  • 原文地址:https://www.cnblogs.com/dxd-success/p/4272294.html
Copyright © 2011-2022 走看看