Pie

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6158    Accepted Submission(s):
2343

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
3 3
4 3 3
1 24
5
10 5
1 4 2 3 4 5 6 5 4 2
 



Sample Output
25.1327
3.1416
50.2655
 
 
 
这一题大意是:总共有m个蛋糕,要分给K+1个人,求能分给每个人,且面积最大的蛋糕面积!
用二分法来查找!
 
 
 
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define PI acos(-1.0)//PI的精度最好大点
using namespace std; double L[] , man;
int n,k,i; bool F(double x)
{
int sum=;
for(i=;i<n;i++)
sum+=(int)(L[i]/x);//sum的作用是记录当要求的面积为x时,最多能分多少整块
return sum>=(k+);//如果能分的比要求的多就返回真
}
void qw()
{
double l=,r=man,mid;
while(r-l>1e-)//二分法
{
mid=(l+r)/;
if(F(mid))
l=mid;
else
r=mid;
}
printf("%.4lf\n",r);
}
int main()
{
int N,T;
scanf("%d",&N);
while(N--)
{
scanf("%d%d",&n,&k);
man =;
for(i=;i<n;i++){
scanf("%d",&T);
L[i] = PI*T*T; if(man < L[i]) man = L[i];//找出最大的蛋糕面积
}
qw();
}
return ;
}
 

Pie--hdu1969(二分法)的更多相关文章

  1. 分派pie(二分法)

    2.问题描述 我的生日要到了!根据习俗,我需要将一些派分给大家.我有N个不同口味.不同大小的派.有F个朋友会来参加我的派对,每个人会拿到一块派(必须一个派的一块,不能由几个派的小块拼成:可以是一整个派 ...

  2. HDU 1969 Pie(二分法)

    My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...

  3. UVA 12097 LA 3635 Pie(二分法)

    Pie My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numbe ...

  4. UVALive 3635 Pie(二分法)

    简单的二分法应用,循环1000次精度就满足要求了. #include<iostream> #include<cstdio> #include<cstdlib> #i ...

  5. hdu 1969 Pie (二分法)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  6. 二分法经典习题——HDU1969

    #include <iostream>#include <cmath>#include <iomanip>using namespace std; double p ...

  7. HDU1969:Pie(二分)

    Pie Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissio ...

  8. Hdu1969 Pie 2017-01-17 13:12 33人阅读 评论(0) 收藏

    Pie Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissio ...

  9. POJ 3122 pie (二分法)

    Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have ...

  10. POJ-3122.Pie(二分法最大化平均值)

    二分法的主题思路就是逐步逼近,所以这道题的思路自然一目了然,做题思路也是... 本题大意:题主过生日,它买了N块半径为R[ i ],高为1的圆柱形蛋糕,现在他要将这N块蛋糕等分给F + 1个人,为了好 ...

随机推荐

  1. 玩转Firefox侧栏

    偶然看到煎蛋网的"玩转firefox侧栏",才注意到它. Firefox侧栏有啥不一样? Firefox可以在侧栏中打开网页. 于是,一系列玩法就出来了... 侧栏打开在线应用 G ...

  2. Unix 环境高级编程 (APUE) 之 网络 IPC:套接字

    一起学 Unix 环境高级编程 (APUE) 之 网络 IPC:套接字 . . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级 ...

  3. BZOJ 2535 Plane 航空管制2

    http://www.lydsy.com/JudgeOnline/problem.php?id=2535 思路:对于1,我们只需要每个点比前驱大就可以了,然后满足尽量优. 对于第二问,我们先求出这个点 ...

  4. LeetCode_Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  5. 为什么学微信小程序开发

    微信小程序是什么? 触手可得,不用安装,不体验过自己是想不到的 ---张小龙 小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜 一下即可打开应用.也体现了“用 ...

  6. Linux FTP安装与简单配置

    1.检測是否原有启动 ps -ef|grep vsftpd 2.检測是否有安装包 rpm -qa|grep vsftpd 3.假设有输出.查看状态并启动 service vsftp status  - ...

  7. 如何对应用服务性能问题诊断(Tomcat、Weblogic中间件)

    在我们web项目中,我们常见的web应用服务器有Tomcat.Weblogic.WebSphere.它们是互联网应用系统的基础架构软件,也叫“中间件”,负责处理动态在页面请求,并为应用提供了名字.事务 ...

  8. 用maven骨架生成项目速度慢的问题

    最近从IntelliJ Idea 14的Community版本切换到Ultimate. 问题出现 最近从IntelliJ Idea 14的Community版本切换到Ultimate,key是从网络上 ...

  9. stagefright框架(七)-Audio和Video的同步

    讲完了audio和video的处理流程,接下来要看的是audio和video同步化(synchronization)的问题.OpenCORE的做法是设置一个主clock,而audio和video就分别 ...

  10. NPOI兼容 excel2003,2007版本

    根据项目需要,需要对excel进行导入导出,所以选择NPOI,优点在这里就不详细介绍了,下面进入正题. public int Import(string path) { IList<Studen ...