hdoj 1969 Pie【二分】
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6320 Accepted Submission(s):
2383
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.
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.
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).
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 10100
#define pi 3.1415926
double a[MAX];
int n,m;
int f(double x)
{
int i,s=0;
for(i=0;i<n;i++)
s+=(int)(a[i]/x);
return s;
}
int main()
{
int j,i,t;
double max,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%lf",&k);
a[i]=k*k*pi;
}
double l=0,r=200000000000.0,mid;
while(r - l > 1e-6)
{
mid = (r + l)/2;
if(f(mid) >= m+1)//算上自己
l=mid;
else
r=mid;
}
printf("%.4lf\n",r);
}
return 0;
}
hdoj 1969 Pie【二分】的更多相关文章
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- HDU 1969 Pie(二分,注意精度)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1969 Pie [二分]
1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...
- (step4.1.2)hdu 1969(Pie——二分查找)
题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...
- hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Me ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- 题解报告:hdu 1969 Pie(二分)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- hdu 1969 pie 卡精度的二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 【HDOJ】1969 Pie
二分. #include <stdio.h> #include <math.h> ; ]; int main() { int case_n, n, f, m; double r ...
随机推荐
- 原生与jqueryDOM
总结与复习原生与jquery的DOM操作. 获取元素节点: $(".class") $("#id") $(".class div") $(& ...
- vector预分配空间溢出
vector 当一个vector预分配的存储空间用完之后,为维护其连续的对象数组,它必须在另外一个地方重新分配大块新的(更大的)存储空间,并把以前已有的对象拷贝到新的存储空间中去. // A clas ...
- Qt5下的常见问题————C1083
很多像我一样刚开始学习Qt的时候都会遇到这样的问题.例如"fatal error C1083: 无法打开包括文件:“QApplication”: No such file or direct ...
- ACM hdu 1008 Elavator
Elevator其实是一道水题,思路也很简单,但不知道怎么也不能AC,后来看了别人的再比较自己的以后找到错误. 在判断奇偶数之后的语句时,我用了if() else if(),这是不能AC的原因,这种 ...
- js隔行变色
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Node.js(window)基础(2)——node环境下的模块,模块间调用
参考:http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/00143450241959 ...
- javascript判断设备类型-手机(mobile)、安卓(android)、电脑(pc)、其他(ipad/iPod/Windows)等
使用device.js检测设备并实现不同设备展示不同网页 html代码: <!doctype html> <html> <head> <meta charse ...
- js 通过function来定义函数
什么是函数: 函数是完成某一功能的代码段. 函数是可重复执行的代码段. 函数方便管理和维护. 自定义一个函数: 通过function关键字来定义一个函数. 语法: function 函数名称([可 ...
- Android中用Application类实现全局变量
最近在项目中,遇到了application这个类,开始不知道有什么用,经过学习后才知道它的用途也蛮大的,举个例子,如果想在整个应用中使用全局变量,在java中一般是使用静态变量,public类型:而在 ...
- OC语言-02面向对象的三大特性
01封装 #import <Foundation/Foundation.h> @interface Student : NSObject { //@public 成员变量尽量不使用 int ...