POJ-3122 Pie 解题报告(二分) 平分派饼
来源:互联网 发布:万维软件 编辑:程序博客网 时间:2024/05/09 06:23
链接- J - Pie
题目大意:有N个饼平分给F+1个人,求每人能分到的最大面积(饼可以切分不能合,每块切后剩下的扔掉。。。好浪费~~~)。
#include<stdio.h>int N,F,r,n;double s[10000+5];#define pi 3.141592653589793238462643383279502884197169399#define esp 1e-6int main(){scanf("%d",&n);while(n--){int i;double smax=0;scanf("%d%d",&N,&F);for(i=0;i<N;i++){scanf("%d",&r);s[i]=r*r*pi;if(s[i]>smax) smax=s[i];}double l=0,r=smax,mid;while(r-l>esp){mid=l+(r-l)/2;int cur=0;for(i=0;i<N;i++){cur=cur+int(s[i]/mid);}if(cur>=F+1)l=mid;elser=mid;}printf("%.4lf\n",l);}return 0;}
代码解析:二分思路,就是在一个区间内二分快速查找到一个固定的值,可能我们之前不知道它的具体值,但是能确定在某个精度范围内是一定能找到它的,它也就是答案了。。。
这个题目,不断取面积值,设先取S0,可得每块饼最多能切出几个S0,将总和与人数F+1比较,如果符合则继续二分,直到满足精度则退出循环。
- POJ-3122 Pie 解题报告(二分) 平分派饼
- POJ 3122 Pie 解题报告(二分)
- POJ 3122 Pie解题报告
- POJ-1129 Pie 解题报告
- POJ 3122 Pie(二分)
- 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 (高精度+二分)
- B树、B-树、B+树、B*树
- delphi TComponent类(1)
- 关于C++第三次作业反馈
- delphi TComponent类 2
- 关于android SDK安装Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list-1.xml出错
- POJ-3122 Pie 解题报告(二分) 平分派饼
- Syntax error: Bad for loop variable解决办法
- 有什么资格抱怨?
- Linux启动过程(从执行init到用户登录部分)
- ssh中Connection is read-only问题的产生原因与解决方法
- CRM Extensibilities -01- Solution
- mmiowb的使用场景
- 个人Java编码规范2
- 关于上一篇文章《B-树及B+树》的bug