分馅饼 Pie
Pie
链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C
题目:
|
Problem 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.
|
|
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
3 |
|
Sample Output
25.1327 |
题意:
有n个馅饼,有f个朋友,接下来是n个馅饼的半径。然后是分馅饼,
要求大家都要一样大,形状没什么要求,但都要是一整块的那种,也就说不能从两个饼中
各割一小块来凑一块。
题目要求我们分到的饼尽可能的大。 分析:
用二分法查找,
把0设为l,把y设为r。mid=(l+r)/2;
以mid为标志,如果所有的饼可以分割出f+1《还有自己》个mid,那么返回1,说明每个人可以得到的饼的体积可以
大于等于mid;如果不能分出这么多的mid,那么返回0,说明每个人可以得到饼的体积小于mid。
注意精度
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double pi=acos(-1.0); //用反余弦求pi
const int maxn=;
double sum,y;
int n,a[maxn],f;
double b[maxn];
int xz(double m)
{
int x=,i;
for(i=;i<n;i++)
{
x+=(int)(b[i]/m);
}
if(x>=f+)
return ;
else return ;
}
22 void slove()
{
double l=0.0,r=y,mid=;
while((r-l)>1e-) //精度问题
{
mid=(l+r)/;
if(xz(mid)) l=mid;
else r=mid;
}
printf("%.4f\n",l);
}
int main()
{
int i,t;
cin>>t;
while(t--)
{
sum=0.0;
cin>>n>>f;
for(i=;i<n;i++)
{
cin>>a[i];
b[i]=a[i]*a[i]*pi;
sum+=b[i];
}
y=sum/(f+);
slove();
}
return ;
}
分馅饼 Pie的更多相关文章
- hdu1969Pie(根据体积二分,分馅饼)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- [SinGuLaRiTy] 分治题目复习
[SInGuLaRiTy-1025] Copyrights (c) SinGuLaRiTy 2017. All Rights Reserved. [POJ 1905] 棍的膨胀 (Expanding ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- ACM pie
我的生日快到了,传统上我正在做馅饼.不只是一个馅饼,不,我有N个,各种口味和各种尺寸. 数量为F我的朋友会来到我的聚会,每个人都得到一个馅饼. 这应该是一块馅饼,而不是几个小块,因为看起来很乱.这一块 ...
- poj3122--二分加贪心
大致题意: 就是公平地分披萨pie 我生日,买了n个pie,找来f个朋友,那么总人数共f+1人 每个pie都是高为1的圆柱体,输入这n个pie的每一个尺寸(半径),如果要公平地把pie分给每一个人(就 ...
- POJ 3122 Pie(二分+贪心)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22684 Accepted: 7121 Special Ju ...
- HDU1969 Pie(二分搜索)
题目大意是要办生日Party,有n个馅饼,有f个朋友.接下来是n个馅饼的半径.然后是分馅饼了, 注意咯自己也要,大家都要一样大,形状没什么要求,但都要是一整块的那种,也就是说不能从两个饼中 各割一小块 ...
- POJ3122Pie(二分)
http://poj.org/problem?id=3122 题意 :这个题最主要的就是审题要仔细,翻译不要漏句子.题目讲的是我要过生日,要给好友分馅饼(还有自己也想要一块),怕引起不公,所以每个人大 ...
- Android系统概述
一.Android的诞生 Android这一词最先出现在法国作家利尔亚当在1886年发表的科幻小说<未来夏娃>中,作者将外表像人类的机器起名为Android,这也就是Android小人名字 ...
随机推荐
- php mysql PDO基本操作
<?php $dbh = new PDO('mysql:host=localhost;dbname=localhost', 'root', ''); $dbh->setAttribute( ...
- java 访问 usb
java 要访问 usb 设备,通常要自己写c/c++代码,然后再用 java 访问这些组件,以达到控制usb设备的目的.但现在有一个开源组件 libusb 帮我们做好了访问usb设备的封装(包括wi ...
- FAST特征点检测
Features From Accelerated Segment Test 1. FAST算法原理 博客中已经介绍了很多图像特征检测算子,我们可以用LoG或者DoG检测图像中的Blobs(斑点检测) ...
- poj 1816 (Trie + dfs)
题目链接:http://poj.org/problem?id=1816 思路:建好一颗Trie树,由于给定的模式串可能会重复,在原来定义的结构体中需要增加一个vector用来记录那些以该节点为结尾的字 ...
- Android基本认识
AndroidManifest.xml file missing! 是因为开始想当然的用中文当project名 no launcher activity found 第一次运行出了点问题,no lau ...
- 智能车学习(二十三)——浅谈心得体会
因为毕竟是竞赛,跟学校挂钩,没办法开源代码和算法完成思路,所以不能详细写太多,如果可以等价交换的话,应该还是可以向领导申请一下的. 在厦大信科通信系,参加这个比赛,大家都觉得性 ...
- Linux内核分析--操作系统是如何工作的
“平安的祝福 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ” 一.初 ...
- 【maven 报错】maven项目执行maven install时报错Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
在使用maven新建的web项目中,执行 执行如上的这两个操作,报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-co ...
- java.util.List接口的方法subList()的使用注意事项
JDK中,List接口有一个实例方法List<E> subList(int fromIndex, int toIndex), 其作用是返回一个以fromIndex为起始索引(包含),以to ...
- DNS常用命令
ipconfig/ifconfig 显示网络信息 nslookup host 查询域名对应的ip同时也显示了网关地址 cat /etc/resolv.conf 查看本地dns服务器地 ...