UVAlive 3635 (13.08.23)
来源:互联网 发布:mysql事务原理 编辑:程序博客网 时间:2024/05/17 21:38
Problem C - Pie
Time limit: 1 second
My birthday is coming up and traditionally I'm serving pie. Not justone pie, no, I have a numberN of them, of various tastes andof various sizes. F of my friends are coming to my party andeach 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 onewhole pie though.
My friends are very annoying and if one of them gets a bigger piecethan the others, they start complaining. Therefore all of them shouldget equally sized (but not necessarily equally shaped) pieces, even ifthis leads to some pie getting spoiled (which is better than spoilingthe party). Of course, I want a piece of pie for myself too, and thatpiece should also be of the same size.
What is the largest possible piece size all of us can get? All thepies 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. Thenfor each test case:
- One line with two integers N and F with 1 ≤N, F ≤ 10000: the number of pies and the number offriends.
- One line with N integers ri with 1 ≤ri ≤ 10000: the radii of the pies.
Output
For each test case, output one line with the largest possible volumeV such that me and my friends can all get a pie piece of sizeV. The answer should be given as a floating point numberwith an absolute error of at most 10-3.Sample Input
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
题意:
主人开Party, 厨房有n个派, 邀请了f个小伙伴, 加上自己一共是f+1个小伙伴
然后, 主人分发派, 但是每个人要分到相同大小的派, 且只能是一整块~(一块完完整整的挖掉一小块也算一整块, 但是不许两块及两块以上拼凑)
我们要做的就是求出, 每个人最大能分到多大块的派呢?
做法:
二分法求解!!
一开始的每块大小的边界是: 最小为0, 最大的为 把总面积加起来除以人数(最理想的情况)
然后题目要求误差不超过 10的负三次方~ (这算是二分递归的边界了)
AC代码:
#include<stdio.h>#include<math.h>const double PI = acos(-1);int n, f;int trueF;double R[12345];double search(double l, double r) { if(r-l < 1e-6) return l; double mid = (l + r) / 2.0; int tSumF = 0; //临时参数, 表示这种情况下饼能分给几个人 for(int i = 0; i < n; i++) tSumF += R[i] / mid; if(tSumF >= trueF) //能分更多的人, 表明饼切小了 return search(mid, r); else //这是切大了 return search(l, mid);}int main() { int T; scanf("%d", &T); while(T--) { scanf("%d %d", &n, &f); trueF = f + 1; //真正的人数加上自己~ double sumR; //表示总大小 for(int i = 0; i < n; i++) { scanf("%lf", &R[i]); R[i] = R[i] * R[i] * PI; sumR += R[i]; } printf("%.4lf\n", search(0, sumR/trueF)); } return 0;}
- UVAlive 3635 (13.08.23)
- UVAlive 2322 (13.08.23)
- UVAlive 2519 (13.08.24)
- UVALive - 3635 Pie
- UVALIVE 3635 Pie 二分
- uvalive 3635(贪心)
- UVALive - 3635 Pie
- UVALive - 3635 Pie
- UVALive - 3635 Pie 二分
- UVALive 3635 Pie
- UVALive 3635-Pie-二分
- UVALive 3635 Pie 【二分】
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- Java中间件JMS(一)之ActiveMQ入门
- wikioi p1160 蛇形矩阵
- LBP算子
- 中山大学超级计算学院2014年招收免试硕士研究生情况简介
- MFC规则dll中获取当前模块句柄
- UVAlive 3635 (13.08.23)
- ubuntu 中Rhythmbox的乱码解决方案
- redis rehash实现
- 如何在Win7中安装使用超级终端Hyper Terminal
- uC/OS 学习
- seo基础入门问问问之二内容质量、更新频率、相关性
- C++传值,传址,引用的区别
- Android 看内存的方式
- restrict关键字