poj 3122 (二分查找)
链接:http://poj.org/problem?id=3122
Pie
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 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 编号要小的牛, 叫你根据上述信息还原出原始的牛的编号序列 分析 ...
随机推荐
- 电脑远程工具:mstsc
外网远程控制:电脑远程连接在开始程序中搜:mstsc 然后直接敲IP地址 工具:dell sonicwall netextender.exe mstsc.exe 内网远程控制:使用TeamVi ...
- 【python cookbook】【字符串与文本】9.将Unicode文本统一表示为规范形式
问题:确保所有的Unicode字符串都拥有相同的底层 解决方案:为解决同一个文本拥有多种不同的表示形式问题,应该先将文本统一表示为规范形式,这可以通过unicodedata模块来完成, unicode ...
- grads 读取浓度值
- Redis常用命令速查 02_转
一.Key Key命令速查: 命令 说明 DEL 删除给定的一个或多个 key,不存在的 key 会被忽略,返回值:被删除 key 的数量 DUMP 序列化给定 key,返回被序列化的值,使用 RES ...
- Hibernate,JPA注解@ManyToMany
@ManyToMany默认处理机制,当双向多对多关联中没有定义任何物理映射时, Hibernate根据以下规则生成相应的值: 关联表名: 主表表名+_下划线+从表表名: 关联到主表的外键名:从表用于关 ...
- linux连接远程服务器提示拒绝访问
如上图,出现的问题是因为端口号错误,如果不是正常连接的端口号,那么就是端口号被恶意更改! 解决方案: 关掉或者开启需要的端口号注释!
- 微信支付 APP 支付方式的服务器端处理程序
对于微信的APP的支付,客户服务说只能通过微信开放平台申请.后来在公众帐号确实发现了证据: 微信支付在申请的时候就比较严(麻烦),对服务类的一些支付,本来商品就是虚拟的,所以需要将商品描述的比较详细 ...
- 微信利用PHP创建自定义菜单的方法
在使用通用接口前,你需要做以下两步工作:1.拥有一个微信公众账号,并获取到appid和appsecret(在公众平台申请内测资格,审核通过后可获得)2.通过获取凭证接口获取到access_token注 ...
- win2003 服务器安全设置详细介绍
第一步:一.先关闭不需要的端口 我比较小心,先关了端口.只开了3389 21 80 1433(MYSQL)有些人一直说什么默认的3389不安全,对此我不否认,但是利用的途径也只能一个一个的穷举爆破, ...
- var_dump(is_writeable(ini_get("session.save_path")));
var_dump(is_writeable(ini_get("session.save_path")));