Pie(二分)
ime Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 8930 | Accepted: 3235 | 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
- 题意:过生日,有f+1个人(加上主人),去分n个尺寸不同的圆柱型的pie,其高为1.要注意n个pie分别不同,每个人分得的必须是同一个pie上的。问平均每个人最多可分得多少。
思路:二分,先找出上下界,下界为0,上界是n个pie中尺寸最大的那个,即每个人得到整个pie,而且是最大的那个。
不断二分,若求出的人数大于f+1,说明现在分得的pie小了,更改min值,否则,更改max值;
- #include<stdio.h>
- #include<math.h>
- const double PI = 3.1415926535898;
- const double eps = 1e-;
- int main()
- {
- int test;
- scanf("%d",&test);
- while(test--)
- {
- int n,f;
- double V[];
- double min,max,mid;
- min = 0.0;
- max = 0.0;
- scanf("%d %d",&n,&f);
- f += ;//加上主人共f+1人;
- for(int i = ; i < n; i++)
- {
- scanf("%lf",&V[i]);
- V[i] = V[i]*V[i];
- if(max < V[i])
- max = V[i];
- }
- while(max - min > eps)
- {
- mid = (max+min)/;
- int people = ;
- for(int i = ; i < n; i++)
- people += V[i]/mid;//每个人分得的pie必须来自于同一个pie,直接取整就行;
- if(people < f)
- max = mid;
- else min = mid;
- }
- double ans = PI*mid;
- printf("%.4lf\n",ans);
- }
- return ;
- }
Pie(二分)的更多相关文章
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- HDU 1969 Pie(二分,注意精度)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 【POJ 3122】 Pie (二分+贪心)
id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...
- Pie(二分)
http://poj.org/problem?id=3122 题意:将n个圆柱体的不同口味的pie分给m个人,要求每个人分得的pie必须体积相同,且来自于一块pie(即:只分得一种口味的pie),求最 ...
- Pie(二分POJ3122)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12985 Accepted: 4490 Special Ju ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- 【hoj】2651 pie 二分查找
二分查找是一个非常主要的算法,针对的是有序的数列,通过中间值的大小来推断接下来查找的是左半段还是右半段,直到中间值的大小等于要找到的数时或者中间值满足一定的条件就返回,所以当有些问题要求在一定范围内找 ...
- HDU1969:Pie(二分)
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- B - Pie (二分)
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...
- UVaLive 3635 Pie (二分)
题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...
随机推荐
- [转] 使用NVM快速搭建NODE开发环境
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node 本文主要介绍最近自己碰到的几个坑以及搜索到的相应解决方案: 如何快速搭 ...
- java中关于public class
在编写类的时候可以使用两种方式定义类: public class定义类: class定义类: 1,如果一个类声明的时候使用了public class进行了声明,则类名称必须与文件名称完 ...
- JS(一)
额, 写了一堆, 待机win8崩溃, 重启之后只剩光秃秃的界面, 以后再填吧, 下次一定要一口气把博客写完,中间不能放下干其他事. 1.对象,以及对象与方法联合: var bob = new Obje ...
- <html:text> Id属性
可能 会遇到这样 的问题,需要通过document.getElementById得到<html:text>标签的id, 可是据说ie设置property后id就是一样的了,不过具体没有去测 ...
- IEqualityComparer 去重
1.去除list里某重复字段值的数据(相当于group by) public class CorrController { //方法 public void DoGet() { List<tes ...
- Android开发手记(30) 触摸及手势操作
触摸操作在现在智能手机系统中起到举足轻重的作用,本文将对安卓中的触摸以及一些简单手势的操作进行简单的介绍. 1.触摸 首先是关于触摸的判断,有两种方法可以判断的触摸操作. (1)setOnTouchL ...
- oracle 查看用户表数目,表大小,视图数目等
查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * fr ...
- power desinger 学习笔记<一>
如果一张表有 很多字段(多于30个),那么一个一个复制粘贴,耗时耗力.可以偷懒,事先编辑好 sql脚本,然后把sql脚本导入 power designer,是不是很方便? 看下面的 1. 打开Pow ...
- JS特殊符号
反斜杠用来在文本字符串中插入省略号.换行符.引号和其他特殊字符. 代码 输出 \' 单引号 \" 双引号 \& 和号 \\ 反斜杠 \n 换行符 \r 回车符 \t 制表符 \b 退 ...
- Java设计模式(学习整理)----装饰模式
1.概念: (在我看来,模式就像是是一种思想,在这种思想的指引下,对代码和结构的一番加工和整合而已!都是套路!) 装饰模式又称包装(Wrapper)模式,是以对客户端透明的方式扩展对象的功能,是继承关 ...