Pie (二分)
发布日期:2021-10-16 05:05:08
浏览次数:16
分类:技术文章
本文共 3403 字,大约阅读时间需要 11 分钟。
Pie
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 107 Accepted Submission(s) : 19
Special Judge
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:<ul><li>One line with two integers N and F with 1 ≤ N, F ≤ 10 000: the number of pies and the number of friends.<li>One line with N integers ri with 1 ≤ ri ≤ 10 000: the radii of the pies.</ul>
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<sup>3</sup>.
Sample Input
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
Source
PKU
题意:
有f+1个人分n快披萨,每个人要求分得的体积意义,且披萨只能被切开不能重新组合,求每个人能分到的最大的体积。
思路:
用二分法,注意题目输入的是半径,我们不直接寻找半径,而是转换成面积寻找面积。一般遇到实数问题且范围不是很大时,由于精度差问题,我们一般考虑将数扩大相应的倍数,来去掉小数点,以便我们后来的计算。代码:
#include#include #include #include #include #include #include
另一种没扩大倍数的代码:(关键还是将半径随即转换成面积,然后来找面积)
#include#include #include #include #include #include #include
心得:
熟悉熟悉二分的基本套路,学会分析问题。
转载地址:https://blog.csdn.net/sinat_37668729/article/details/77043549 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月03日 04时51分02秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【Android】Android之WiFi开发应用示例
2019-04-26
【Android】 Android adb常见问题整理
2019-04-26
【Android】 Android体系结构图
2019-04-26
【Android】 Android中spinner下拉列表的使用
2019-04-26
说说在 python 中,如何删除左右两边不需要的字符
2019-04-26
说说如何管理 Spring Boot 中的起步依赖
2019-04-26
说说如何在 Linux 中,新建账号
2019-04-26
说说如何在 linux 中搭建 FTP 服务
2019-04-26
说说如何在 Python 的正则表达式中使用分组
2019-04-26
说说 Python 正则表达式的匹配类型
2019-04-26
说说 Python 的贪心和非贪心匹配策略
2019-04-26
说说在 Python 中,如何找出所有字符串匹配
2019-04-26
说说 Python 正则表达式中的那些字符类别码
2019-04-26
说说 Spring Boot 的条件化注解
2019-04-26
说说如何使用 Python 在 word 中创建表格
2019-04-26
Python 基础知识考题与解答(2020 版)
2019-04-26
说说 Oracle 的 SYSDATE 函数
2019-04-26
说说 Oracle 的 NVL 与 NVL2 函数
2019-04-26
说说 TCP 协议以及三次握手流程
2019-04-26
说说 Oracle 的 TRUNC 函数
2019-04-26