Pie

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6320    Accepted Submission(s):
2383

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
 
题解:求自己和朋友可以分得的最大馅饼面积
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 10100
#define pi 3.1415926
double a[MAX];
int n,m;
int f(double x)
{
int i,s=0;
for(i=0;i<n;i++)
s+=(int)(a[i]/x);
return s;
}
int main()
{
int j,i,t;
double max,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%lf",&k);
a[i]=k*k*pi;
}
double l=0,r=200000000000.0,mid;
while(r - l > 1e-6)
{
mid = (r + l)/2;
if(f(mid) >= m+1)//算上自己
l=mid;
else
r=mid;
}
printf("%.4lf\n",r);
}
return 0;
}

  

hdoj 1969 Pie【二分】的更多相关文章

  1. HDU 1969 Pie(二分查找)

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

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

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

  3. HDU 1969 Pie [二分]

    1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...

  4. (step4.1.2)hdu 1969(Pie——二分查找)

    题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...

  5. hdu 1969 Pie(二分查找)

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

  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. 【HDOJ】1969 Pie

    二分. #include <stdio.h> #include <math.h> ; ]; int main() { int case_n, n, f, m; double r ...

随机推荐

  1. OC基础-day03

    1#pragma mark - Day03_01_对象作为方法的返回值 1) 对象是可以作为方法的返回值的,返回值应该写这个类指针类型. - (MkDog *)buyDog; 代表方法执行完毕之后,有 ...

  2. 一、C# 概述

    1.托管执行环境 2.程序集 3.关键字:C#保留字 4.除了C#定义的关键字之外,开发者可以提供他们自己的名称,编程语言将这些名称称为标识符 5.如果关键字包含一个"@"前缀,那 ...

  3. vs2013 使用vs调试器,发现调试器显示的数据错误。查看内存,发现内存是正确的。

    有可能只是调试器的问题,程序可以正常运行的! 网上没找到此种情况解释.感觉有可能是那里堆被破坏了.

  4. Observer 模式

    Observer模式要解决的问题为:建立一个一(Subject)对多(Observer)的依赖关系,并且做到当“一”变化的时候,依赖这个“一”的多也能够同步改变.最常见的一个例子就是:对同一组数据进行 ...

  5. requirejs 笔记

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  6. Android ART简介

    一.    Android ART简介 Android DEX/ODEX/OAT文件

  7. 如何删除github上的项目

    如果大伙用过github,那么就会知道它上面没有明显的选项可以让你直接删除掉一个Repositories或者项目.因此对很多github的新手来说一开始也常觉得这个事情比较犯难.这里我给大家简单介绍一 ...

  8. 通过javascript实现1~100内能同时被2和3整除的数并生成如下表格

    请通过javascript实现1~100内能同时被2和3整除的数并生成如下表格: <!DOCTYPE html><html lang="en"><he ...

  9. 到底该如何入门Keras、Theano呢?(浅谈)

    目前刚刚开始学习Theano,可以说是一头雾水,后来发现Keras是对Theano进行了包装,直接使用Keras可以减少很多细节程序的书写,它是模块儿化的,使用比较方便,但更为细节的内容,还没有理解, ...

  10. hadoop 各种counter 解读

    http://blog.sina.com.cn/s/blog_61ef49250100uxwh.html 经过了两天的休息与放松,精神饱满了吧?上星期我们学习了MapReduce的过程,了解了其基本过 ...