hdu1969(二分)

来源:互联网 发布:市场调研数据分析 编辑:程序博客网 时间:2024/05/18 05:28

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);

#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>using namespace std;double pi = acos(-1.0);int N,F,t;double v[11111];int main(){    int T;    int N,F;    int i;    int r;    double left,right,mid;    double v[10011];    scanf("%d",&T);    while(T--)    {        scanf("%d%d",&N,&F);        F++;//加上自己        right = 0;        for(i=0; i<N; i++)        {            scanf("%d",&r);            v[i] = pi * r * r;            right = max(right, v[i]);//找出面积最大的饼,为二分上界        }        left=0;        mid=(left + right) / 2;        while(right - left >= 0.0000001)//精度要求        {            t=0;            for(i=0; i<N; i++) t += (int)(v[i]/mid);            if(t >= F)            left = mid;            else            right = mid;            mid = (left + right) / 2;        }        printf("%0.4lf\n",mid);    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 母亲性格内向儿子也是内向怎么办 我儿子不爱吃怎么办啊 孩子练字就是记不住怎么办 孩子不愿意和小朋友玩怎么办 丈夫去世了婆婆不喜欢儿媳妇怎么办 高考看不下去书怎么办 在东莞读书读不成高中怎么办 嗓子哑了怎么办土方法 小孩舌头太长太大讲话不清楚怎么办 一周岁不喝奶粉怎么办 一岁的宝宝不吃奶粉怎么办 小孩不爱吃饭怎么办吃什么药 小孩这几天不爱吃饭怎么办 宝宝这几天不爱吃饭怎么办 想看书看不进去怎么办 宝宝3岁不爱看书怎么办 4岁宝宝不爱看书怎么办 1岁宝宝不爱看书怎么办 孩子一看书就哭怎么办 我不想读大专了怎么办 一年级的小孩不爱学习怎么办 高中的孩子不爱学习怎么办 9个月宝宝肠胃不好怎么办 孩子高烧过后干呕不爱吃饭怎么办 母乳涨奶发烧了怎么办 涨奶发烧了怎么办啊 2岁宝贝不吃饭怎么办 4个月的婴儿厌食怎么办 2个月婴儿厌食怎么办 3个月宝宝厌奶怎么办 没胃口吃不下饭怎么办 小孩吃多了积食怎么办 孩子吃撑了难受怎么办 卵巢早衰月经量少怎么办 7岁孩吃饭少消瘦怎么办 宝宝3岁不吃饭怎么办 小孩吃多了吐了怎么办 6岁儿童越来越瘦怎么办 7岁儿童不吃饭怎么办 天热宝宝不好好吃饭怎么办 天热宝宝不爱吃饭怎么办