博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3122 Pie
阅读量:4602 次
发布时间:2019-06-09

本文共 2558 字,大约阅读时间需要 8 分钟。

/*PieTime Limit: 1000MS  Memory Limit: 65536K Total Submissions: 6186  Accepted: 2327  Special Judge DescriptionMy 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.InputOne 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.OutputFor 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 Input33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2Sample Output25.13273.141650.2655二分水题,但如果没想到用2分可能就比较复杂...想了很久也没什么好方法,还是借鉴了一个二分函数A了*/#include
#include
#define PI 3.14159265358979323846 // 这么写也很妙const double pi=acos(-1.0);#define EPS 1e-7 //精度需要注意,太大可能超时,太小会WA#define abs(x) ((x)>=0?(x):-(x)) int n,f;double pie[10010];double search(double a,double b) //二分法遍历{ double left=a,right=b,mid; while(abs(left-right)>EPS) { mid=(left+right)/2; int i,num=0; for(i=0;i
=mid) { ++num; t-=mid; } if(num>=f) break; } if(num>=f) left=mid; else right=mid; } return mid;}int main(){// freopen("in.txt","r",stdin); int m; scanf("%d",&m); while(m--) { double left=0,right=0,mid=0; int i; scanf("%d%d",&n,&f); ++f;//注意自己也要算进去 for(i = 0 ; i < n ; i++) { scanf("%lf",&pie[i]); pie[i]*=pie[i]; //r^2 if(pie[i]>right) right = pie[i]; } printf("%.4lf\n",PI*search(left,right)); } return 0;}
 
 

转载于:https://www.cnblogs.com/Felix-F/archive/2012/03/11/3223701.html

你可能感兴趣的文章
_bzoj2005 [Noi2010]能量采集
查看>>
pat 团体天梯赛 L3-010. 是否完全二叉搜索树
查看>>
烟草MES系统介绍-序
查看>>
优先队列小结
查看>>
线程安全与可重入函数之间的区别与联系
查看>>
bat批处理中如何获取前一天日期
查看>>
{Nodejs} request URL 中文乱码
查看>>
异常及日志使用与项目打包
查看>>
努力,时间,坚持,自律
查看>>
真三 bug PT的凤凰
查看>>
???动态SQL
查看>>
js错误处理与调试理论和办法
查看>>
Binding.StringFormat不起作用的原理和解决
查看>>
css hack兼容写法
查看>>
CSS两列布局 一边固定 一边自适应
查看>>
Hadoop2.6.0 动态增加节点
查看>>
图论的一些概念、定理
查看>>
WebView用法
查看>>
Lecture 3: Planning by Dynamic Programming
查看>>
用flash代替图片IMG,设置动态效果链接
查看>>