HDU 1969 Pie(二分,注意精度)
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16554 Accepted Submission(s): 5829
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.
InputOne 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.
OutputFor 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 题意:N种蛋糕,每个半径给出,要分给F+1个人,要求每个人分的体积一样(形状可以不一样),而且每人只能分得一种蛋糕(不能多种蛋糕拼在一起),求每人最大可以分到的体积。
思路:初始下界为0,上界为最大的蛋糕体积,二分求出结果。
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include<cmath>
using namespace std ;
#define MAX 10005
double S[MAX] ;
double N , F ;
int main()
{
int T ;
double PI=acos(double(-));
scanf("%d" , &T) ;
while(T--)
{
//cin >> N >> F ;
scanf("%lf%lf",&N,&F) ;
F ++ ;
double ri ;
double ma = 0.0 ;
for(int i = ; i < N ; i ++)
{
//cin >> ri ;
scanf("%lf" ,&ri) ;
S[i] = PI*ri*ri ;
if(S[i] > ma) ma = S[i] ;
}
double l = , r =ma ,mid ;
int cnt ;
while(r - l >= 0.0000001)
{
mid = (l + r) / ;
cnt = ;
for(int i = ; i < N ; i ++)
{
cnt += int(S[i]/mid) ;
}
if(cnt >= F)
{
l = mid ;
}
else r = mid ;
}
printf("%.4f\n",l) ;
}
}
HDU 1969 Pie(二分,注意精度)的更多相关文章
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- (step4.1.2)hdu 1969(Pie——二分查找)
题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...
- HDU 1969 Pie [二分]
1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...
- hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Me ...
- hdu 1969 pie 卡精度的二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 题解报告:hdu 1969 Pie(二分)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- HDU 1969 Pie(二分法)
My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...
- HDU 1969 Pie
二分答案+验证(这题精度卡的比较死) #include<stdio.h> #include<math.h> #define eps 1e-7 ; double a[ff]; d ...
随机推荐
- Asynchronous Programming Model (APM)异步编程模型
https://msdn.microsoft.com/zh-cn/library/ms228963(v=vs.110).aspx 一.概念 An asynchronous operation that ...
- JAVA_返回一个数值的相反数的几种方式.
一个方法接收一个int类型值,需要返回它的相反数. 如传入1,返回-1 传入-22,返回22 最简单的方式是return 0-number; 还有其他方式: public class Kata { p ...
- NO.1 在Eclipse中安装Maven插件安装详解
前言 本来是没打算写博客的,作为一个13年毕业的菜鸟,自认为水平太渣写不出什么好文章,但是前些日子看到一篇鼓励性质的文章说,技术人员的成长靠的就是点点滴滴的积累,博客内容不一定包含多么高深的内容,但是 ...
- Thinking in java note1
Part information collecting from http://blog.csdn.net/leonliu06/article/details/78638841 1. 如果已经定义了一 ...
- Python XML解析和处理
movies.xml <collection shelf = "New Arrivals"> <movie title = "Enemy Behind& ...
- [原][osgearth]FAQ
参考:http://docs.osgearth.org/en/latest/faq.html Common Usage How do I place a 3D model on the map? Th ...
- 使用Zend studio+WAMP来调试Wordpress后台的PHP程序的一些非常关键的信息(原创)
一.Zend studio代码格式化快捷键:选中代码,Ctrl+Shift+F( 注意,在英文输入发状态下使用!) .Zend studio实用快捷键 :http://www.zendstudio.n ...
- rails安装使用版本控制器的原因。
使用版本控制器的原因: 你没有系统根权限,所以你没有别的选择 你想要分开运行几个rails 系统 ,并且这几个rails有不同的Ruby版本.使用RVM就可以轻松做到. 没有什么新鲜的先安装xcode ...
- HDU - 5917 水题
题意:n个点m条边,找点集个数,点集满足有任意三个点成环,或者三个点互不相连 题解:暴力复杂度O(n^5/120*O(ok))==O(能过) //#pragma comment(linker, &qu ...
- idea配置echache.xml报错Cannot resolve file 'ehcache.xsd'
解决方法: 打开settings->languages&frameworks->schemas and dtds ,添加地址 http://ehcache.org/ehcache. ...