Pie

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

 
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.

InputOne 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. 
OutputFor 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种蛋糕,每个半径给出,要分给F+1个人,要求每个人分的体积一样(形状可以不一样),而且每人只能分得一种蛋糕(不能多种蛋糕拼在一起),求每人最大可以分到的体积。

思路:初始下界为0,上界为最大的蛋糕体积,二分求出结果。

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include<cmath>
using namespace std ;
#define MAX 10005
double S[MAX] ;
double N , F ;
int main()
{
int T ;
double PI=acos(double(-));
scanf("%d" , &T) ;
while(T--)
{
//cin >> N >> F ;
scanf("%lf%lf",&N,&F) ;
F ++ ;
double ri ;
double ma = 0.0 ;
for(int i = ; i < N ; i ++)
{
//cin >> ri ;
scanf("%lf" ,&ri) ;
S[i] = PI*ri*ri ;
if(S[i] > ma) ma = S[i] ;
}
double l = , r =ma ,mid ;
int cnt ;
while(r - l >= 0.0000001)
{
mid = (l + r) / ;
cnt = ;
for(int i = ; i < N ; i ++)
{
cnt += int(S[i]/mid) ;
}
if(cnt >= F)
{
l = mid ;
}
else r = mid ;
}
printf("%.4f\n",l) ;
}
}
												

最新文章

  1. iOS 开发快速导引:iOS 程序框架【草】
  2. 混搭.NET技术
  3. 【知识积累】SBT+Scala+MySQL的Demo
  4. makefile 学习笔记
  5. 使用HttpClient 4.3.4 自动登录并抓取中国联通用户基本信息和账单数据,GET/POST/Cookie
  6. 4、界面前端设计师要阅读的书籍 - IT软件人员书籍系列文章
  7. discuz内置常用CSS代码分析
  8. Apache Shiro 使用手册(一)Shiro架构介绍
  9. 用c#开发微信 (6) 微渠道 - 推广渠道管理系统 1 基础架构搭建
  10. MysqlHelper类
  11. 高级C++开发工程师综合测试题(风林火山)
  12. js源码保护
  13. 修改IE8搜索框为指定搜索引擎,如CSDN、百度知道等
  14. Mysql 5.6 新特性
  15. 【Teradata】使用arcmain进行不落地数据迁移(管道)
  16. matlab多个曲面如何画在一个坐标系中的疑问
  17. dialog记录
  18. Python--os的常见方法
  19. OpenCV入门(1)- 简介
  20. CPU单核多核区别【转载】

热门文章

  1. python 列表元素替换以及删除
  2. Qt532_QWebView做成DLL供VC/Delphi使用_Bug
  3. Java回顾之反射
  4. gif&amp;png&amp;jpg&amp;webp
  5. 快速使用CSS 弹性盒子
  6. node+websocket创建简易聊天室
  7. UVA-11419 SAM I AM (最小点覆盖)
  8. @ModelAttribute运用详解(二十一)
  9. R语言rJava包安装载入及JAVA环境配置
  10. ansible入门01