题目链接

Problem Description
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.

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:
---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
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
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

题解:将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(二分搜索)的更多相关文章

  1. hdu 1969 Pie(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others)    Me ...

  2. HDU 1969 Pie(二分法)

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

  3. HDU 1969 Pie(二分查找)

    Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...

  4. HDU 1969 Pie(二分,注意精度)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  5. hdu 1969 Pie (二分法)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  6. HDU 1969 Pie【二分】

    [分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...

  7. 题解报告:hdu 1969 Pie(二分)

    Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...

  8. hdu 1969 pie 卡精度的二分

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  9. HDU 1969 Pie

    二分答案+验证(这题精度卡的比较死) #include<stdio.h> #include<math.h> #define eps 1e-7 ; double a[ff]; d ...

随机推荐

  1. Webservice WCF WebApi

    注明:改编加组合 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在.net平台下,你有很多的选择来构建一个HTTP Service ...

  2. XML+AJAX

  3. HDU 5903 Square Distance

    $dp$预处理,贪心. 因为$t$串前半部分和后半部分是一样的,所以只要构造前一半就可以了. 因为要求字典序最小,所以肯定是从第一位开始贪心选择,$a,b,c,d,...z$,一个一个尝试过去,如果发 ...

  4. SQL 默认数据库被误删

    我今天也遇到了,自己解决了.这是我总结的:(不管这帖子沉到哪里了) 删除了SQL服务器默认数据库,无法连接服务器,用户[]登录失败. 1,使用管理员账户修改此用户的默认数据库.    企业管理器,展开 ...

  5. 在Eclipse中用TODO标签管理任务(Task)

    Elipse为Java项目的时候,有一个很人性化的“任务管理”功能,利用这个功能可以方便地将项目中一些需要处理的任务记录下来.先来看看“任务管理”是怎么使用的吧.下面这个类在Class和name 属性 ...

  6. Xcode使用小结1

    工程项目 -> General->launch Screen file这个如果没有设置,则app的可见范围为3.5inch(APP的可见范围是由启动界面决定的) PUSH方法是在navig ...

  7. cocos坐标系及坐标转换

    cocos2dx的坐标系是以左下角为(0,0)点, 向右上为正 世界坐标系:相对于屏幕位置的坐标表示 节点坐标系:相对于父节点的坐标表示 可以相互转换: /** * 将世界坐标转换成节点坐标,忽略锚点 ...

  8. Spring Boot--war发布

    启动main类继承SpringBootServletInitializer,并重写"protected SpringApplicationBuilder configure(SpringAp ...

  9. 关于Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 的详解

    1. http://bbs.wuyou.com/forum.php?mod=viewthread&tid=303679&fromuid=396698

  10. ubuntu下安装teamviewer

    Ubuntu 14.04 安装teamviewer出现安装32位依赖包 wget http://download.teamviewer.com/download/teamviewer_i386.deb ...