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 编号要小的牛, 叫你根据上述信息还原出原始的牛的编号序列 分析 ...
随机推荐
- java设置环境变量小工具
unit MainUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Fo ...
- iOS 学习笔记 一 (2015.02.05)
一:Xcode6输入框设置为 keyboard type设置为Number Pad弹不出键盘的解决办法 问题:Can't find keyplane that supports type 4 fo ...
- Mac OS finder : 显示和隐藏文件[夹] show and hide files or folders
Finder默认是不显示隐藏文件[夹]的,要显示出怎么办? 要显示的话,可以GUI(graphic user interface)和CLI(command line interface)两种方式 CL ...
- new和malloc的区别
1.malloc与free是C++/C语言的标准库函数,new/delete是C++的运算符 2.new出来的指针是直接带类型信息的,而malloc返回的都是void*指针. 3.new 建立的是一个 ...
- Window驱动开发
驱动开发 参考文章: Windbg+Vmware驱动调试 http://blog.csdn.net/xuepiaosong/article/details/8236702 驱动调试攻略(WinDbg) ...
- oracle进制-10进制跟2进制互转
CREATE OR REPLACE FUNCTION NUMBER_TO_BIT(V_NUM NUMBER) RETURN VARCHAR IS V_RTN );--注意返回列长度 V_N1 NUMB ...
- C++11 std::function用法
转自 http://www.hankcs.com/program/cpp/c11-std-function-usage.html function可以将普通函数,lambda表达式和函数对象类统一起来 ...
- hibernate 对应关系级联的意思
hibernate的关联关系,重点在理解级联cascade和inverse 1.cascade一般用在级联保存,级联更新,级联删除上 1.1cascade注解有两种,一种是基于hibernate注解 ...
- Android 5.1 - 状态栏充电标志问题
Android 5.1 Ubuntu14.04 SourceInsigh 电量已满,插着USB头,观察Settings - Battery,电量为100%,状态为full,但仍有充电图标rust 之 ...
- ZOJ 3860: - Find the Spy
3860 - Find the Spy Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...