zoukankan      html  css  js  c++  java
  • Pie

    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
    题意:小明过生日朋友来做客,小明用披萨招待他们,有大小不一样的很多披萨,一个朋友分一块,这一块必须是整的,不能一块块的凑起来,并且小明也想吃,每个人必须相同;
    解题思路:从最大的饼里求出来最大能分得饼m,然后再1~m之间用二分求最大分饼数,二分的题真是***(脏话自动屏蔽)圆周率需要3.14159265358979323846!!!!
    代码(g++)
    #include
    #include
    #include
    #define maxn 10010
    using namespace std;
    double pie[maxn];
    double maxn_pie(int n,int f,double pie[])//理想中的能分到的最大披萨
    {
        double sum=0;
        for(int i=0;i
            sum+=pie[i];
        return sum/(f+1);//总共f个朋友加我
    }

    int main()
    {
        //freopen("in.txt", "r", stdin);
        int t,n,f;
        double m_pie=-1,p=0,p1,p2;
        scanf("%d",&t);
        for(int i=0;i
        {
            memset(pie,0,sizeof(pie));
            m_pie=-1;
            scanf("%d%d",&n,&f);
            for(int j=0;j
            {
                scanf("%lf",&pie[j]);
                //注意!!!!pi的精度最少得是我写的这么多,要不后果自负!!!
                pie[j]=pie[j]*pie[j]*3.14159265358979323846;//每个饼的面积(因为高都是1,所以分面积
                //就行了)
                if(pie[j]>m_pie)
                    m_pie=pie[j];//把最大面积的披萨求出来
            }
            //printf("最大的披萨是%.4lf ",m_pie);
            p1=0;
            p2=m_pie;
            while(p2-p1>1e-6)//开始在最大的披萨中二分来求最大部分披萨了
            {
                p=(p1+p2)/2;
                //printf("p=%.4lf ",p);
                int ans=0;
                for(int i=0;i
                    ans+=(int)(pie[i]/p);//剩下的不要了
                if(ans>=f+1)
                    p1=p;
                else if(ans
                    p2=p;
            }
            printf("%.4f ",p1);
        }
    }
  • 相关阅读:
    JsonParse类
    vs2013提交项目到github
    js选中select
    按每20条分组查询
    批量修改图片格式
    当前日期后10天日期
    C#生成不重复随机数的方法
    接收端通过Request.InputStream读取流
    C#文件流的读写
    C#中HttpWebRequest的用法详解
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5781641.html
Copyright © 2011-2022 走看看