题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的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 切糕大师 二分的更多相关文章

  1. UVaLive 3635 Pie (二分)

    题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...

  2. uvalive 3635 Pie

    https://vjudge.net/problem/UVALive-3635 题意: 有F+1个人要分n个蛋糕,他们得到的蛋糕的面积必须是一样的,但是每个蛋糕必须是整块的蛋糕,而不是有多块蛋糕拼成的 ...

  3. UVALive 3635 Pie(二分法)

    简单的二分法应用,循环1000次精度就满足要求了. #include<iostream> #include<cstdio> #include<cstdlib> #i ...

  4. 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 ...

  5. 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 ...

  6. POJ 3122 Pie (贪心+二分)

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...

  7. UVALive 3635 分派

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  8. UVALive 6656 Watching the Kangaroo --二分

    题意:给你一些区间,再查询一些点,问这些点与所有区间形成的最小距离的最大值.最小距离定义为:如果点在区间内,那么最小距离为0,否则为min(pos-L[i],R[i]-pos). 解法:当然要排个序, ...

  9. LA 3635 Pie 派 NWERC 2006

    有 f + 1 个人来分 n 个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,并且面积要相同.求每个人最多能得到多大面积的派(不必是圆形). 这题很好做,使用二分法就OK. 首先在读取所有派 ...

随机推荐

  1. android邮件发送几种方式

    android中发送邮件我大概发现了3种,代码如下 package src.icetest; import org.apache.commons.mail.EmailException; import ...

  2. c++类模板中静态成员变量的声明定义

    我们知道,c++中,类的静态成员是要在.cpp文件中定义的,如果在.h中定义,会出现重复定义. 但是在写类模板时,一般所有的代码都是放在.h文件中的,如果要做分离是一件很麻烦的事.那如果出现了静态成员 ...

  3. [转载]CTO和技术总监区别

    原文地址:http://blog.sina.com.cn/s/blog_6024cfa90101cb0h.html 技术总监(Chief Technical Officer)与CTO(Chief Te ...

  4. (译)"usermod"命令使用完全指导---15个练习例程截图

    "usermod"命令使用完全指导---15个练习例程截图 By Babin Lonston Under: Linux Commands On: November 11, 2014 ...

  5. iOS断言

    来自:http://my.oschina.net/panyong/blog/205573 在看到xmpp项目中的一些代码时,看到如下,不懂该代码是啥意思, 如下: NSAssert(_xmppStre ...

  6. spring-android的使用【转】

    android + Spring RESTful 简单登录 (spring3实现服务端 rest api)  https://github.com/spring-projects/spring-and ...

  7. 树形控件CTreeCtrl的使用

    树形控件在界面编程中应用十分普遍,如在资源管理器中和树形结构显示书的文件夹等,我们一步步研究树形控件的使用. 在对话框界面上首先拖动创建一个树,一般我们改变三个属性: Has Buttons显示带有& ...

  8. 【枚举+小技巧】【TOJ4115】【Find the number】

    题目大意 找到一个最小的奇数 约数个数为n 结果mod10^9+7 根据 约数个数=(p1+1)*(p2+1)............ 将n 枚举分解成连乘式.(枚举个数,dfs) 比较大小 log ...

  9. LeetCode Day4——Factorial Trailing Zeroes

    /* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...

  10. 引言:Canvas绘图API快速入门

    引言:Canvas绘图API快速入门 在接触HTML5的初学者包括我都在很多地方见到非常炫的一些页面,甚至好多学习HTML5的开发者都是冲着Web端的页游去的,那么HTML5那么绚丽的页面效果以及游戏 ...