【二分答案】【POJ3122】【Northwestern Europe 2006】Pie
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 10629 | Accepted: 3744 | Special Judge | ||
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 arecoming 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 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
还是附上中文题目吧
13 派(NWERC 2006, LA 3635)
有F+1个人来分N个圆形派(半径不同),每个人得到的必须是一整块派,而不是几块拼在一起,且面积要相同。求每个人最多能得到多大面积的派(不必是圆形)。
【输入格式】
输入的第一行为数据组数T。每组数据的第一行为两个整数N和F(1≤N,F≤10 000);第二行为N个整数ri(1≤ri≤10 000),即各个派的半径。
【输出格式】
对于每组数据,输出每人得到的派的面积的最大值,精确到10-3。
思路:
显然二分答案 没什么好解释的了
附白书解释:
这个问题并不是“最小值最大”问题,但仍然可以采用二分答案方法,把问题转化为“是否可以让每人得到一块面积为x的派”。这样的转化相当于多了一个条件,然后求解目标变成了“看看这些条件是否相互矛盾”。
会有怎样的矛盾呢?只有一种矛盾:x太大,满足不了所有的F+1个人。这样,我们只需要算算一共可以切多少份面积为x的派,然后看看这个数目够不够F+1即可。因为派是不可以拼起来的,所以一个半径为r的派只能切出[πr2/x]个派(其他部分就浪费了),把所有圆形派能切出的份数加起来即可。代码如下。
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double PI=acos(-1);
const int maxn=10000+5;
int N,F,r;
double radius[maxn];
double ans;
double squre; bool ok(double area)
{
int sum = 0;
for(int i = 1; i <= N; i++) sum += floor(radius[i] / area);
return sum >= F;
} int getans()
{
double i=0,j=squre,m;
while(j-i>1e-6)
{
m=(j+i)/2;
if(ok(m)) i=m;
else j=m;
}
ans=i;
return 0;
}
int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
squre=-1;
scanf("%d%d",&N,&F);
F++;
for(int i=1;i<=N;i++)
{
scanf("%d",&r);
radius[i]=r*r*PI;
squre=max(squre,radius[i]);
}
getans();
printf("%.4lf\n",ans);
}
return 0;
}
【二分答案】【POJ3122】【Northwestern Europe 2006】Pie的更多相关文章
- 【二分答案】 【POJ3497】 【Northwestern Europe 2007】 Assemble 组装电脑
Assemble Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3171 Accepted: 1013 Descript ...
- LibreOJ #2006. 「SCOI2015」小凸玩矩阵 二分答案+二分匹配
#2006. 「SCOI2015」小凸玩矩阵 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- POJ 3122 Pie【二分答案】
<题目链接> 题目大意: 将n个半径不一但是高度为1的蛋糕分给 F+1个人,每个人分得蛋糕的体积应当相同,并且需要注意的是,每个人分得的整块蛋糕都只能从一个蛋糕上切下来,而不是从几个蛋糕上 ...
- POJ 3122 Pie 二分答案
题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...
- UVA 12097 Pie(二分答案)
题目链接: 这道题虽然不是一道典型的二分答案题,但同样也可以用二分答案来做. 来二分面积为$area$的派,然后看看条件是否矛盾. 与其矛盾的便是$f+1$个人是否每个人都会有. 一个半径为$r$的派 ...
- 【二分答案+贪心】解决“最小值最大”问题(UVa 12124 - Assemble)
Problem A - Assemble Time limit: 2 seconds Recently your team noticed that the computer you use to p ...
- Poj 3261 Milk Patterns(后缀数组+二分答案)
Milk Patterns Case Time Limit: 2000MS Description Farmer John has noticed that the quality of milk g ...
- CH Round #72树洞[二分答案 DFS&&BFS]
树洞 CH Round #72 - NOIP夏季划水赛 描述 在一片栖息地上有N棵树,每棵树下住着一只兔子,有M条路径连接这些树.更特殊地是,只有一棵树有3条或更多的路径与它相连,其它的树只有1条或2 ...
- [CF752E]Santa Claus and Tangerines(二分答案,dp)
题目链接:http://codeforces.com/contest/752/problem/E 题意:给n个橘子,每个橘子a(i)片,要分给k个人,问每个人最多分多少片.每个橘子每次对半分,偶数的话 ...
随机推荐
- [Python学习笔记][Python内置函数]
Python 常用内建函数 比较基础的列表 abs(x) 求绝对值 pow(x,y) 返回x的y次方,等同于x**y round(x[,小数位数]) 对x进行四舍五入,若不指定位数,则返回整数 chr ...
- js 代码命名规范系列
在微博上看到一个段子 “老子哪天出任ceo迎娶白富美走上人生巅峰之后,一定要雇两个长腿大熊的妹子.一个帮我想变量名字,一个帮我想git commit的message!” 可以看出 命名方方面面的问题困 ...
- asp.net mvc 访问.html文件
把html页面放在除Views文件夹外的任意文件夹,如Htmls--123.html,url直接访问便可,如 http://yourname/htmls/123.html 可以在路由表中排出不需要路由 ...
- Python3.5入门学习记录-模块
模块让你能够有逻辑地组织你的Python代码段. 把相关的代码分配到一个 模块里能让你的代码更好用,更易懂. 模块也是Python对象,具有随机的名字属性用来绑定或引用. 简单地说,模块就是一个保存了 ...
- 使用do...while的方法输入一个月中所有的周日
do{ var date = Number(prompt('请输入一个月的总天数')); var start = (prompt('请输入一个月的一号是周几')); for(var i=0;i< ...
- 设计模式 之 Organizing the Catalog 组织目录
Design patterns vary in their granularity and level of abstraction. Because thereare many design pat ...
- 在Python3.5下安装和测试Scrapy爬网站
1. 引言 Scrapy框架结构清晰,基于twisted的异步架构可以充分利用计算机资源,是爬虫做大的必备基础.本文将讲解如何快速安装此框架并使用起来. 2. 安装Twisted 2.1 同安装Lxm ...
- 蜘蛛牌(hdu 1584 DFS)
蜘蛛牌 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Dropbox 用什么语言开发的?(Python在各个平台都是全能的,特别是有PyObjC真没想到)
Dropbox 绝大部分是用 Python 开发的.用到 Python 的地方有:服务器后台.客户端.Dropbox 网页版前段.API 后台.数据分析. 在服务器端.桌面版客户端使用的是 Pytho ...
- Asp.net管道 (第二篇)
从请求进入ASP.NET工作者进程,直至它到达最终的处理程序之前要经过一系列的步骤和过程,这个步骤和过程称为ASP.NET处理管道. Asp.net的处理管道流程如下: 语言描述如下: Asp.net ...