HDU 1669 & poj 3122 pie

来源:互联网 发布:mysql 1728 编辑:程序博客网 时间:2024/05/09 22:31

Pie
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 11288Accepted: 3939Special Judge

Description

HDU 1669  poj 3122  pie - 风未定 - NGUNAUJMy 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:
  • 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
原创粉丝点击