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 ...
随机推荐
- scrapy中的canonicalize_url【转】
转自:http://www.leyle.com/archives/canonicalize_url.html 思考一下:对url进行规范化处理是否是必须的?因为这一步处理涉及到编码转换,对于一个网页的 ...
- BZOJ 2333 【SCOI2011】 棘手的操作
题目链接:棘手的操作 网上的题解大部分都是在线用可并堆艹……但是树高严格\(\log\)的可并堆我不会啊……还是离线大法好…… 我们可以先把所有的合并操作用并查集给处理好,把得到的森林记录下来.然后, ...
- 使用由 Intel MKL 支持的 R
我们通常使用的 R 版本是单线程的,即只使用一个 CPU 线程运行所有 R 代码.这样的好处是运行模型比较简单且安全,但是它并没有利用多核计算.Microsoft R Open(MRO,https:/ ...
- Java语言的垃圾回收机制
java语言从诞生开始,一个吸引人眼球的功能就是垃圾回收,想一想C++中时不时的内存泄漏,当时感觉写java代码直是一种享受呀. 和.NET的引用计数不同,java的垃圾回收机制采取的是有向图 ...
- mongo 增删改查
1. use foobar2. show dbs3. show collections4. db.system.indexes.find()5. db.persons.find()6. db.pers ...
- BooStrap4文档摘录: 1. Layout
文档: https://getbootstrap.com/docs/4.1/layout/overview/ w3c的案例:很直观: https://www.w3schools.com/bootst ...
- HDU-5700-贪心/stl
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- windows使用git记录
1.免密码clone远程服务器代码开启ssh 生成私钥公钥 命令:查看自己配置的邮箱 git config user.name git config user.email 生成密钥:邮箱填写上面查看出 ...
- bzoj2212
题解: 线段树合并 比较一下哪一种方案的逆序对少 代码: #include<bits/stdc++.h> using namespace std; ; typedef long long ...
- 『转』Emsisoft Anti-Malware 8刷Key教程 - 文字版
先分主机和客机,下载好 EAM8安装包 和 30天重置工具EAM Trial Reset 1.1.exe 1. 主机安装 Emsisoft Anti-Malware 8 并激活30天试用版 如果已 ...