UVALive 3635 Pie 切糕大师 二分
题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的。
做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又没说每个pie都要分完,分不完的留给工作人员吃嘛。
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: live3652.cpp
* Create Date: 2013-09-10 00:40:36
* Descripton: binary, greedy
*/ #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std; const int MAXN = 10010;
const double PI = acos(-1.0); int n, f, t;
double a[MAXN], Max; bool judge(double x) {
int sum = 0;
for (int i = 0; i < n; i++)
sum += a[i] / x;
if (sum >= f + 1) return true;
return false;
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &f);
for (int i = 0; i < n; i++) {
scanf("%lf", &a[i]);
a[i] = PI * a[i] * a[i];
Max = max(Max, a[i]);
}
double low = 0, mid;
while (Max - low > 1e-5) {
mid = low + (Max - low) / 2;
if (judge(mid)) low = mid;
else Max = mid;
}
printf("%.4lf\n", low);
}
return 0;
}
UVALive 3635 Pie 切糕大师 二分的更多相关文章
- UVaLive 3635 Pie (二分)
题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...
- uvalive 3635 Pie
https://vjudge.net/problem/UVALive-3635 题意: 有F+1个人要分n个蛋糕,他们得到的蛋糕的面积必须是一样的,但是每个蛋糕必须是整块的蛋糕,而不是有多块蛋糕拼成的 ...
- UVALive 3635 Pie(二分法)
简单的二分法应用,循环1000次精度就满足要求了. #include<iostream> #include<cstdio> #include<cstdlib> #i ...
- UVA 12097 LA 3635 Pie(二分法)
Pie My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numbe ...
- Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- POJ 3122 Pie (贪心+二分)
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...
- UVALive 3635 分派
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVALive 6656 Watching the Kangaroo --二分
题意:给你一些区间,再查询一些点,问这些点与所有区间形成的最小距离的最大值.最小距离定义为:如果点在区间内,那么最小距离为0,否则为min(pos-L[i],R[i]-pos). 解法:当然要排个序, ...
- LA 3635 Pie 派 NWERC 2006
有 f + 1 个人来分 n 个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,并且面积要相同.求每个人最多能得到多大面积的派(不必是圆形). 这题很好做,使用二分法就OK. 首先在读取所有派 ...
随机推荐
- Inno Setup 安装前卸载原程序(转)
很多時候我們需要在安裝文件之前卸載原有的程序而不是覆盖安装,本文的code就是实现了这样的功能. 实现原理是:從注冊表'UninstallString'項中读取卸载信息,用Exec进行静默卸载. 下面 ...
- la 3942 Rember_前缀树
#include <iostream> #include<cstdio> #include<cstring> using namespace std; #defin ...
- 安装 SQL Server 2008 R2 的硬件和软件要求(转)
以下各部分列出了安装和运行 SQL Server 2008 R2 的最低硬件和软件要求.有关 SharePoint 集成模式下的 Analysis Services 的要求的详细信息,请参阅硬件和软件 ...
- mysql插入大量数据
创建实验表: CREATE TABLE `a` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` char(50) NOT NULL, `type` ch ...
- ASP.NET MVC 学习之路-5
本文在于巩固基础 数据库开发模式: 1.数据库优先开发模式 2.模型优先开发模式 EntityFramework学习之一 最简单的一个案例 第一步创建模型 public class Student { ...
- javascript 兼容各个浏览器的事件
- Android中 Http请求
HttpClient public class MainActivity extends Activity { private Button button; @Override protected v ...
- 关于oracle卸载没有卸载完全的问题
1.关闭oracle所有的服务.可以在windows的服务管理器中关闭: 2.打开注册表:regedit 打开路径: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlS ...
- global变量
在函数体内定义的global变量,函数体外可以使用,在函数体外定义的global变量不能在函数体内使用, $global $a; $a=123; function f() { echo $a; //错 ...
- html css float left与 float right的使用说明
点评: CSS中很多时候会用到浮动来布局,也就是经常见到的float:left或者float:right,简单点来说,前者是左浮动(往左侧向前边的非浮动元素飘,全是飘得元素的话,就按照流式来浮动从左到 ...