poj 3122 (二分查找)
链接:http://poj.org/problem?id=3122
Pie
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 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. Input One line with a positive integer: the number of test cases. Then for each test case:
Output For 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 Sample Output 25.1327 Source |
…………………………………………………………………………………………
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
一开始没理解题意,粗心了,原来是(f+1)个人
然后直接二分就出来结果了
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream> using namespace std;
#define eps 1e-6
#define MAXX 10005
#define PI 3.14159265359 double area(double x)
{
return PI*x*x;
} int n,m;
double str[MAXX]; int judge(double x)
{
int sum=;
for(int i=; i<n; i++)
sum+=(int)(str[i]/x);
return sum;
} int main()
{
int t,i,j;
double tmp;
scanf("%d",&t);
while(t--)
{
double maxx=0.0,left=0.0,right;
scanf("%d%d",&n,&m);
for(i=; i<n; i++)
{
scanf("%lf",&tmp);
str[i]=area(tmp);
maxx=maxx<str[i]?str[i]:maxx;
}
right=maxx;
while(right - left > eps)
{
double mid=(right+left)/2.0;
if( judge(mid) >= m + )
left=mid+eps;
else right=mid-eps;
}
printf("%.4lf\n",left);
}
return ;
}
poj 3122 (二分查找)的更多相关文章
- POJ 3122 二分
大致题意: 就是公平地分披萨pie 我生日,买了n个pie,找来f个朋友,那么总人数共f+1人 每个pie都是高为1的圆柱体,输入这n个pie的每一个尺寸(半径),如果要公平地把pie分给每一个人(就 ...
- 【POJ】3122 Pie [二分查找]
题目地址:http://poj.org/problem?id=3122 二分每块饼的体积.为了保证精度,可以先二分半径的平方r*r,最后再乘以PI.要注意一点,要分的人数要包括自己,及f+1. #in ...
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- POJ 3122 & 3258 & 3273 #二分
以下三道都是经典二分,道理都差不多,代码就贴在一起了. POJ 3122 POJ 3258 POJ 3273 POJ 3122: #include<iostream> #inc ...
- poj 2452(RMQ+二分查找)
题目链接: http://poj.org/problem?id=2452 题意:在区间[1,n]上找到满足 a[i]<a[k]<a[j] (i<=k<=j) 的最大子区间 (j ...
- 【POJ 3122】 Pie (二分+贪心)
id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- POJ——3061Subsequence(尺取法或二分查找)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11224 Accepted: 4660 Desc ...
- POJ 2182 Lost Cows (树状数组 && 二分查找)
题意:给出数n, 代表有多少头牛, 这些牛的编号为1~n, 再给出含有n-1个数的序列, 每个序列的数 ai 代表前面还有多少头比 ai 编号要小的牛, 叫你根据上述信息还原出原始的牛的编号序列 分析 ...
随机推荐
- 视频处理控件TVideoGrabber如何重新编码视频/音频(2)
在前面的文中<视频处理控件TVideoGrabber如何重新编码视频>已经讲解了部分TVideoGrabber重新编码音频.视频剪辑的内容,下面将继续说明. 重新编码进程 重新编码开始时, ...
- 互联网公司前端初级Javascript面试题
互联网公司前端初级Javascript面试题 1.JavaScript是一门什么样的语言,它有哪些特点?(简述javascript语言的特点)JavaScript是一种基于对象(Object)和事件驱 ...
- input放在a标签里面不能选择input里面的文本,IE9点击失效
input放在a标签里面不能选择input里面的文本,IE9点击失效 在IE浏览器中<input type="text" value="test" /&g ...
- [转]linux主机644、755、777权限详解
转自:http://my.oschina.net/qihh/blog/73135 从左至右,第一位数字代表文件所有者的权限,第二位数字代表同组用户的权限,第三位数字代表其他用户的权限. 从左至右,第一 ...
- MySQL 添加列,修改列,删除列
ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table ...
- centos7.1-64bit安装qtcreator
首先,启用 EPEL Repository: yum -y install epel-release 启用 EPEL Repository 後, 可以用 yum 直接安裝qtcreator: yum ...
- PHP获取不了React Native Fecth参数的解决办法是怎么样呢?
fetch('https://mywebsite.com/endpoint/', { method: 'POST',headers: {'Accept': 'application/json','Co ...
- ImageLoader 图片加裁
// String picurl = article.cateLogo;// ImageLoader.getInstance().displayImage(picurl, holder.cate_Lo ...
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
- Greenplum的全量恢复之gpdbrestore
gpdbrestore命令是对gp_restore命令的一个包装,提供了更灵活的选项,比如,使用gpcrondump自动备份的文件来恢复.使用gpdbrestore恢复必须具备: 1. 存在gpcro ...