HDU 1669 & poj 3122 pie
来源:互联网 发布:mysql 1728 编辑:程序博客网 时间:2024/05/09 22:31
Pie
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 11288Accepted: 3939Special Judge
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.
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
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
Source
Northwestern Europe 2006
和昨天做的题差不多
题目大意:分pie 把n块饼分成f+1块 且均分得到体积尽量大;
集体思路:二分将0作为左边值 总和作为有边值 枚举mid满足可分成f+1块的最大值
#include <iostream>#include <cstring>#include <cstdlib>#include <stdio.h>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <iomanip>#include <list>#include <deque>#include <stack>#define ull unsigned long long#define ll long long#define mod 90001#define INF 0x3f3f3f3f#define maxn 10000+5#define cle(a) memset(a,0,sizeof(a))#define pi 4*atan(1.0)const ull inf = 1LL << 61;const double eps=1.0e-4;using namespace std;bool cmp(int a,int b){ return a>b;}double a[maxn];int t,f,n;double ans;bool check(double x){int num=0;for(int i=1;i<=n;i++){num+=(int)(a[i]/x);}if(num>=f+1)return false;return true;}int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout);cin>>t;while(t--){double l=0.0,r=0.0,b;ans=-1.0;cin>>n>>f;for(int i=1;i<=n;i++){scanf("%lf",&b);a[i]=pi*b*b;r+=a[i];}while(r-l>eps){//eps小点double mid=(l+r)/2.0;if(check(mid)){//分大了r=mid;}else{l=mid;}}printf("%.4lf\n",l);} return 0;}
0 0
- HDU 1669 & poj 3122 pie
- poj 3122 hdu 1969 Pie
- POJ 3122/HDU 1969-Pie-二分法分馅饼
- POJ-3122 Pie
- POJ 3122 Pie 二分
- POJ 3122 Pie 二分
- poj 3122 pie
- POJ 3122 Pie
- poj 3122 la3635 pie
- POJ 3122 Pie
- POJ-3122-Pie
- POJ 3122 Pie
- POJ 3122 Pie
- poj 3122 Pie
- poj 3122 pie
- POJ 3122 Pie
- POJ-3122 Pie
- POJ 3122--Pie
- HDU 4706 Children\'s Day
- Qt(QLabel)实现滚动字幕
- HDU 4708 Rotation Lock Puzzle
- Difference Between Primes----素数筛选
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- HDU 1669 & poj 3122 pie
- HDU 1551 Cable master
- HDU 2602 Bone Collector
- 命运
- 数塔
- 免费馅饼
- A. Winner
- Modified GCD
- HDU 2577 How to Type
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
开远特产
开远住宿
开远美食
开远水泥厂
昆明到开远
开远到昆明
开远机务段
开远是哪里
开远五中
开远五九医院
开远59医院
开远0873信息网
开远旅游景点
开远景点
昆明到开远在哪里坐车
开远妇科医院
开远解化医院
开远火车站
北京开远保安
开远一中
开远home家精品酒店
开远汽车站
开远属于哪个省
昆明到开远多少公里
开远二手市场
开远滇南翠怡酒店
开远招聘信息
开远二手摩托车
开远市
开远县
夜间高速行驶开近光还是远光
欢乐中国行魅力开远
开迪
大众 开迪
大众开迪柴油版
开迪论坛
一汽大众开迪
开迪汽车
大众开迪
电信开钻卡
1qb开钻