POJ 3122 Pie

Source: Internet
Author: User

PieTime Limit: 1000 MS Memory Limit: 65536 KTotal Submissions: 7639 Accepted: 2817 Special JudgeDescriptionMy 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 shoshould be one piece of one pie, not several small pieces since th At 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 shocould 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 shocould 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. inputOne 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. outputFor each te St 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 shoshould be given as a floating point number with an absolute error of at most 10 −3. sample Input33 34 3 31 24510 51 4 2 4 5 6 5 4 2 Sample Output25.13273.141650.2655SourceNorthwestern Europe 2006 sorrow, this Accuracy Problem is really confusing, the train of thought is correct because the Accuracy Problem is stuck there. When I first started to solve the problem, double data was converted into int data and directly converted. Later, when I started to do the problem, because I was in the strong Conversion I didn't add 0.01 errors many times, so I got into the habit of strong conversion to + 0.01. The question I am doing today must not be added. If I add it, I will be wrong, you can directly perform forced conversion. [Cpp] # include <stdio. h> # include <string. h> # include <math. h> # define PI 3.1415926535898 # define EQS 1e-7 double a [11000]; int n, m; int main () {double binary_search (double l, double r); int t, i; double res, max; scanf ("% d", & t); while (t --) {scanf ("% d", & n, & m ); m ++; for (I = 0, max = 0; I <= n-1; I ++) {scanf ("% lf", & a [I]); if (a [I]> max) {max = a [I] ;}} res = binary_search (0, max * PI); printf ("%. 4lf \ n ", res );} Return 0;} int check (double mid) {int s = 0, I; for (I = 0; I <= n-1; I ++) {s + = (int) (a [I] * a [I] * PI/mid);} if (s> = m) {return 1 ;} else {return 0 ;}} double binary_search (double l, double r) {int t; double mid; while (! (Fabs (r-l) <= EQS) {mid = (r + l)/2.0; if (! Check (mid) {r = mid;} else {l = mid;} return l ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.