Pie POJ 3122 二分搜索
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 17324 | Accepted: 5835 | Special Judge |
Description

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 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
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
Source
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 10009
#define N 21
#define MOD 1000000
#define INF 1000000009
const double eps = 1e-;
const double PI = acos(-1.0);
/*
给定n个圆 和 F个朋友
要求把这n个圆 分成(F+1)份 每一份要尽量大!
直接二分搜索 每一份的大小
*/
double s[MAXN];//面积
int n, f;
int sgn(double x)
{
if (fabs(x) < eps)
return ;
else if (x > )
return ;
else
return -;
}
bool check(double x)
{
int cnt = ;
for (int i = ; i < n; i++)
{
cnt += floor(s[i] / x);
}
return cnt >= (f + );
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &f);
double tmp, l = 0.0, r;
for (int i = ; i < n; i++)
{
scanf("%lf", &tmp);
s[i] = PI*tmp*tmp;
r = max(s[i], r);
}
while (sgn(r-l)>)
{
double mid = (l + r) / ;
if (check(mid))
l = mid;
else
r = mid;
}
printf("%.4lf\n", l);
}
}
Pie POJ 3122 二分搜索的更多相关文章
- 【POJ 3122】 Pie (二分+贪心)
id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...
- POJ 3122 & 3258 & 3273 #二分
以下三道都是经典二分,道理都差不多,代码就贴在一起了. POJ 3122 POJ 3258 POJ 3273 POJ 3122: #include<iostream> #inc ...
- Hie with the Pie POJ - 3311
Hie with the Pie POJ - 3311 The Pizazz Pizzeria prides itself in delivering pizzas to its customers ...
- POJ 3122 Pie( 二分搜索 )
链接:传送门 题意:一个小朋友开生日派对邀请了 F 个朋友,排队上有 N 个 底面半径为 ri ,高度为 1 的派,这 F 个朋友非常不友好,非得"平分"这些派,每个人都不想拿到若 ...
- POJ - 3122 Pie(二分)
http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...
- POJ 3122 Pie 二分枚举
题目:http://poj.org/problem?id=3122 这个题就好多了,没有恶心的精度问题,所以1A了.. #include <stdio.h> #include <ma ...
- POJ 3122 Pie
题目大意: 给出n个pie的直径,有f+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少.要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为 ...
- POJ 3122 Pie(二分+贪心)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22684 Accepted: 7121 Special Ju ...
- POJ 3122 Pie (贪心+二分)
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...
随机推荐
- 【已解决】Makefile执行过程中出错:make: *** No rule to make target ` ‘, needed by xxx. Stop(转载)
转自: http://www.crifan.com/makefile_error_make_no_rule_to_make_target_needed_by_stop/ [问题] 有个已有的Makef ...
- E20171005-ts
collapse n. 垮台; (身体的) 衰弱; vt. 使倒塌; 使坍塌; 使瓦解; vi. 崩溃; 倒塌; 折叠; (尤指工作劳累后) 坐 ...
- target属性打开方式
在HTML中target目标的四个参数的用法:1.target="_self"表示:将链接的画面内容,显示在目前的视窗中.(内定值) . 即:同(自己)窗口打开,别的数据还存在,相 ...
- codevs3327选择数字(单调队列优化)
3327 选择数字 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 给定一行n个非负整数a[1]..a[n].现 ...
- [Swift通天遁地]四、网络和线程-(15)程序内购功能
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- layout 自适应详解
@{ ViewBag.Title = "人员查找"; ViewBag.LeftWidth = "200px"; ViewBag.MiddleW ...
- [Luogu 2678] noip15 子串
[Luogu 2678] noip15 子串 题目描述 有两个仅包含小写英文字母的字符串 A 和 B.现在要从字符串 A 中取出 k 个互不重叠的非空子串,然后把这 k 个子串按照其在字符串 A 中出 ...
- mybatis or
这两天项目用到mybatis,碰到and or的联合查询,语句像这样的 select * from table where xxx = "xxx" and (xx1="x ...
- 02--Tomcat总体结构分析一
注:此文章大部分参考大神文档,并且结合自身理解,补充了其他相关知识,谢绝转载. 大神原文地址链接:http://www.ibm.com/developerworks/cn/java/j-lo ...
- CSS——精灵图与背景图片定位
精灵图产生背景: 1.网页上的每张图像都需要向服务器发送一次请求才能展现给用户.2.网页上的图像过多时,服务器就会频繁地接受和发送请求,大大降低页面的加载速度.为了有效地减少服务器接受和发送请求的次数 ...