HDU 1969 Pie(二分搜索)
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.
---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.
题解:将n个蛋糕分给m+1个人,但是每个人只能拿到一块(不能拼凑),每块大小要相同(形状不用相同),问每个人最多能分到多大的蛋糕(面积)。思路是先求出面积,用数组保存,并排序。L为0,R为最大的那个蛋糕的面积,然后二分搜索。
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
using namespace std;
//#define LOCAL
int n,m;
double a[];
bool check(double x)
{
int cnt=;
for(int i=; i<n; i++)
{
cnt+=int(a[i]/x);
if(cnt>=m)return ;
}
return ;
}
bool cmp(double a,double b)
{
return a>b;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
int N;
cin>>N;
while(N--)
{
//int n,m;
cin>>n>>m;
m++;
ms(a);
for(int i=; i<n; i++)
{
cin>>a[i];
a[i]=a[i]*a[i]*PI;
}
sort(a,a+n,cmp);
double l=,r=a[],mid;
if(m<n)n=m;//即使前面m个不够,后面的也没用,这样可以省点时间
while(r-l>1e-)
{
mid=(r+l)/;
if(check(mid))l=mid;
else r=mid;
}
printf("%.4lf\n",l);
}
return ;
}
HDU 1969 Pie(二分搜索)的更多相关文章
- hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Me ...
- HDU 1969 Pie(二分法)
My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...
- 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 ...
- hdu 1969 Pie (二分法)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- 题解报告: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 ...
- HDU 1969 Pie
二分答案+验证(这题精度卡的比较死) #include<stdio.h> #include<math.h> #define eps 1e-7 ; double a[ff]; d ...
随机推荐
- 【angular】angular实现简单的tab切换
html: <div class="list-group" ng-repeat="tab in menuList"> <a href=&quo ...
- HOOK(钩子)函数
安装.卸载钩子的相关函数 钩子类型 按功能分: 1.WH_CALLWNDPROC和WH_CALLWNDPROCRET:使你可以监视发送到窗口过程的消息3.WH_DEBUG 调试钩子4.WH_FO ...
- 【Map】Double Queue
Double Queue Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13258 Accepted: 5974 Des ...
- python字符串和列表
import sys#sys.argv[0] 被设定为指定模块的全名#脚本名和附加参数传入一个名为 sys.argv 的字符串列表.你能够获取这个列表通过执行 import sys,列表的长度大于等于 ...
- 如何让有物理键的手机在ActionBar始终显示更多菜单menu键
仅作记录代码用,功能未能测试成功,在低版本上不存在 sHasPermanentMenuKey 属性,会出现 java.lang.NoSuchFieldException: sHasPermanentM ...
- CodeForces 671A Recycling Bottles
暴力. 每个人找到一个入口,也就是从回收站到这个入口走的路程由人的位置到入口的路程来替代. 因此,只要找两个人分别从哪里入口就可以了.注意:有可能只要一个人走,另一人不走. #pragma comme ...
- 整理一些css在使用中的小技巧(进行中)
1. 消除li排列display:inline-block的间隙 ul{ font-size:; } ul li{ display:inline-block; }
- 【noi openjudge题解】最低通行费
这道题完全没有必要去计算限制时间,把时间当做一个参数来做就行了.知道了这一点之后就可以直接使用DP求解了 #include <algorithm> #include <iostrea ...
- 字串变换 (2002 年NOIP全国联赛提高组)
一道看似非常水的题 大意 :将一个字串 经过几种变换规则变为给定的另一个子串 ,求最小操作数. code[vs] 传送门 洛谷传送门 已知有两个字串 A, B 及一组字串变换的规则(至多6个规则): ...
- es6语法
let定义变量,特性: 1,不允许重复定义 2,不存在预解析 3,变量存在于会块级作用域 即{}内部 const : 定义常量,常量的值不能修改,若常量是对象 对象下的属性可修改. 解构赋值语法: 数 ...