POJ 3122-Pie(二分+精度)
2015-06-04 09:15
411 查看
题目地址:POJ 3122
题意:给出n个pie的直径,有F+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少。要求是分出来的每一份必须出自同一个pi(既当pie大小为3,2,1,只能分出两个大小为2的份,剩下两个要扔掉。)
思路:对每一个人分的大小进行二分。注意讲pi放在最后成,可以提高精度。
Ps:wa了5发,不知道错在哪,然后把输出的%lf改成%f就A了,并不知道为什么。。。sad
题意:给出n个pie的直径,有F+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少。要求是分出来的每一份必须出自同一个pi(既当pie大小为3,2,1,只能分出两个大小为2的份,剩下两个要扔掉。)
思路:对每一个人分的大小进行二分。注意讲pi放在最后成,可以提高精度。
Ps:wa了5发,不知道错在哪,然后把输出的%lf改成%f就A了,并不知道为什么。。。sad
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map> using namespace std; typedef long long LL; const int inf=0x3f3f3f3f; const double pi= acos(-1.0); const double esp=1e-6; const int maxn=10010; double a[maxn]; int main() { int T,n,F; scanf("%d",&T); while(T--){ double low=0,high=0; scanf("%d %d",&n,&F); F+=1; for(int i=0;i<n;i++){ scanf("%lf",&a[i]); a[i]=a[i]*a[i]; high=max(high,a[i]); } double mid; int cnt; while(high-low>esp){ cnt=0; mid=(low+high)/2; for(int i=0;i<n;i++) cnt+=(int)(a[i]/mid); if(cnt>=F){ low=mid; } else high=mid; } printf("%.4f\n",mid*pi); } return 0; }
相关文章推荐
- maven下载源代码,解决中文注释为乱码的问题
- 把Jar文件转成exe安装文件
- Balanced Binary Tree
- C#中this的用法集锦
- C语言数据类型
- python错误总结大全--(一)
- GitBook 配置说明
- LightOJ1030(数学概率与期望)
- Android studio 下获取Android签名证书
- Swftools+FlexPaper实现PDF上传在线预览功能
- Android与服务器交互数据
- scala编程--1为什么选择scala
- JQuery方法查询
- VS2008集成PC-lint
- Ubuntu下VIM的安装及其配置——Linux篇
- CSS核心:再说框模型(Box Model)
- java贪吃蛇
- [优文翻译]002.陪伴我作为程序员的9句名言(9 Quotes that stayed with me as a developer)
- (我总结的实用主义)Loadrunner运行常见错误
- android:scaleType属性