【UVA12097】Pie
来源:互联网 发布:萧山区网络问政 编辑:程序博客网 时间:2024/06/07 21:55
题面
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 com-plaining. 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.
题意
有
n 个饼,半径为ri (ri≤104 ),分给f+1 个人,要求每个人分到的面积是一样的,而且每个人分到的饼是连续的一块(即不能是几个小块凑起来的),求能够分到的最大面积,精确到三位小数
解法
二分:
虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲)
考虑二分面积,下界L=0 ,上界R=∑ni=1π∗ri2 。对于一个中值x 和一张半径为r 的饼来说,这张饼能够分出的最多分数显然是:⌊π∗r2x⌋ ,所以我们只需要求出∑ni=1⌊π∗ri2x⌋ ,判断其与f+1 的关系即可
特别要注意的一点:π的大小!!!,因为r≤104 ,所以r2≤108 ,又因为题目要求精确到三位小数,所以π 就要精确到10-11,即π=3.14159265358
拓展
maze:
分析
maze代码:https://gitee.com/qjlyh/codes/dg3rbnm45xfz7ytjlckhu64
maze数据:https://pan.baidu.com/s/1eS3Z9aq
复杂度
O(
nlog(R−L) )
代码
#include<iostream>#include<cstdlib>#include<cstdio>#include<queue>#define Lint long long intusing namespace std;const double pi=3.141592653589;//79323846const double eps=1e-6;const int MAXN=10010;double r[MAXN],s[MAXN];double n,L,R;int T,f;bool check(double lim){ int ret=0; for(int i=1;i<=n;i++) ret+=(int)(s[i]/lim); return ret>=f;}int main(){ scanf("%d",&T); while( T-- ) { L=R=0; scanf("%lf%d",&n,&f),f++; for(int i=1;i<=n;i++) { scanf("%lf",&r[i]); s[i]=pi*r[i]*r[i]; R+=s[i]; } while( R-L>eps ) { double mid=(L+R)/2; if( check( mid ) ) L=mid; else R=mid; } printf("%.4lf\n",L); } return 0;}
- Uva12097 Pie
- uva12097 pie
- UVa12097 - Pie
- uva12097 Pie
- 【UVA12097】Pie
- uva12097
- 例题1.13 派 UVa12097
- Pie
- Pie
- pie
- Pie
- Pie
- PIE
- Pie
- Pie
- Pie
- Pie
- Pie
- Hyperledger Fabric SDK
- Eclipse快捷键 10个最有用的快捷键
- dorado 7 添加子表
- thrift:swift 命令行生成 IDL文件及Client java代码过程
- 浅谈MIL、SIL、PIL、HIL
- 【UVA12097】Pie
- Mybatis插件PageHelper的使用
- adb命令
- C#计时器的三种实现方法
- 动态规划:求最长公共子串/最长公共子序列
- 优秀新媒体文案的4种必备能力
- 做项目多渠道打包的时候遇到的问题
- Unity3d 判断 IOS 设备网络环境 IPV4 or IPV6
- java实现网易云短信接口