poj 3122 Pie (二分查找)
来源:互联网 发布:韩顺平满汉楼数据库表 编辑:程序博客网 时间:2024/05/21 12:43
链接:poj 3122
题意:我生日派对时,准备了n个圆柱形的pie,半径比一定相同,但高都为1,
邀请了f个朋友,加上自己一共f+1人,需要将n个pie分给f+1个人
要求:每个人分得的pie尺寸要一样大,
并且同一个人所分的pie要是从同一个pie上得到的,n个pie分完后可以有剩余
求:每个人最多可以分多少
分析:因为同一个人所分的pie都来自同一个pie,
若每个人所分的最大体积为a,那么比a小的pie肯定得舍弃。
将每个人最多分得的pie看成半径为r的圆柱,则最大尺寸为PI*r*r*1,
可以用二分算法,下界为0,上界为pie的最大半径
要注意精度问题
#include<stdio.h>#include<math.h>#define PI acos(-1.0)#define eps 1e-8int n,m;double rad[10010];bool judge(double size){ int cnt=0; for(int i=1;i<=n;i++) cnt+=(int)(rad[i]*rad[i]/(size*size)); if(cnt>=m) return true; return false;}double bin_search(double l,double r){ double mid; while(r-l>eps){ mid=(l+r)/2; if(judge(mid)) //判断分该半径的pie是否够分 l=mid; else r=mid; } return mid;}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); m++; double r=0; for(int i=1;i<=n;i++){ scanf("%lf",&rad[i]); if(rad[i]>r) r=rad[i]; } double ansR=bin_search(0.0,r); printf("%.4lf\n",PI*ansR*ansR); } return 0;}
0 0
- poj 3122 Pie (二分查找)
- Pie(POJ--3122【二分查找】
- POJ 3122 Pie 二分查找 +高精度
- POJ 3122 Pie (二分查找)
- POJ 3122 Pie 二分
- POJ 3122 Pie 二分
- poj 3122 Pie (二分)
- Pie - POJ 3122 二分
- POJ 3122 Pie(二分)
- POJ 3122pie(二分)
- POJ 3122 pie 二分
- [poj 3122] Pie 二分
- POJ Pie 3122 (二分)
- POJ 3122 - Pie(二分)
- poj 3122 pie(二分搜索)
- poj 3122 Pie 二分答案
- POJ 3122 Pie【二分答案】
- poj 3122&&hdu1969 Pie(二分)
- 系统调用的实现原理
- How Much Bandwidth Does Your Website Really Need
- java知识 HashMap
- java logger
- 跟我一起写Makefile学习笔记1——文件搜寻&伪目标&静态模式
- poj 3122 Pie (二分查找)
- 第一篇 Object-C快速入门
- 世上没有强大的敌人,只有不够强大的自己
- PHP7和HHVM的性能之争
- 在stm32上使用Arduino IDE(神舟I号为例)
- 简单配置拦截器
- log4j日志管理系统的简单使用说明
- 海量数据处理双层桶
- android文件上传413 nginx [error] 9679#0: *318855 client intended to send too large body: 1593409 bytes