POJ 3122 Pie(二分)
来源:互联网 发布:深锋网络 编辑:程序博客网 时间:2024/05/30 21:58
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.
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
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
题目大意:
我有f个朋友,n个派,每个派有不同的半径,开趴的时候,给每个朋友包括我自己都分一块派,这块派必须来自一个派的一部分(也就是说不接受两块或两块以上来自不同派的块),并且所有人分得的派的面积要相等,形状不限,问最多每人能分得多大面积的派
解题思路:
二分枚举答案,注意一下精度就好
#include <iostream>#include <fstream>#include <cstdio>#include <cmath>#include <map>#include <set>#include <bitset>#include <ctime>#include <cstring>#include <algorithm>#include <stack>#include <queue>#include <vector>#include <list>#define STD_REOPEN() freopen("../in.in","r",stdin)#define STREAM_REOPEN fstream cin("../in.in")#define INF 0x3f3f3f3f#define _INF 63#define eps 1e-5#define MAX_V 100010#define MAX_P 110#define MAX_E 10010#define MAX 32000#define MOD_P 3221225473#define MOD 9901using namespace std;int t,n,f;double s[10010];const double PI=acos(-1.0);int dcmp(double x){return fabs(x)<eps?0:(x<0?-1:1);}int main(){//STD_REOPEN();scanf("%d",&t);while(t--){scanf("%d %d",&n,&f);for(int i=0;i<n;i++){scanf("%lf",&s[i]);s[i]=s[i]*s[i];//为了避免精度问题的出现,这里暂时不乘PI}f++;double l=0,r=200000010.0;double ans=-1.0;while(dcmp(r-l)>0){double mid=(l+r)/2;int cnt=0;for(int i=0;i<n;i++)cnt+=s[i]/mid;//记录当前面积可以分给多少人if(cnt<f)//小于总人数,面积过大,向左枚举r=mid;else//否则向右枚举{ans=max(ans,mid);l=mid;}}printf("%.4f\n",ans*PI);} return 0;}
0 0
- 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 解题报告(二分)
- poj 3122 Pie (高精度+二分)
- poj 3122 Pie 二分(最大化平均值)
- POJ 3122 Pie(简单二分)
- POJ 3122 Pie (二分查找)
- axis webservice调试
- Java内存管理和垃圾回收
- run模式可以启动,debug模式无法启动
- JPA 实体映射
- [leetcode]Majority Element C语言
- POJ 3122 Pie(二分)
- Scheme 语言概要(上)
- CODEVS 1021 玛丽卡 最短路模板题
- 手机淘宝构架演化实践
- uboot 引导kernel杂谈
- 【Qt】QThread::moveToThread
- Scheme 语言概要(下)
- 鼠标马赛克图像部分区域
- 黑马程序员--对象的存储细节