Title Link: Http://codeforces.com/problemset/problem/215/B
Description
The World Programming Olympics medal is a metal disk, consisting of both parts:the first part are a ring with outer radius Of R1 CM, inner radius of R2 Cm(0?<? R2?<? r1)Made of metal with density P1 g/cm3. The second part is a inner disk with radius R2 CM, it is made of metal with density P2 g/cm3. The disk is nested inside the ring.
The Olympic jury decided that R1 Would take one of possible values of x1,? X2,?...,? xn . It is jury to decide which particular value R1 would take. Similarly, the Olympic jury decided that P1 Would take one of possible value of y1,? Y2,?...,? Ym , and P2 Would take a value from list z1,? Z2,?...,? Zk .
According to most ancient traditions the ratio between the outer ring mass m outand the inner disk mass m inMust equal, where A,? B is constants taken from ancient books. Now, to-start making medals, the jury needs to take values for R1 , P1 , P2 and calculate the suitable value of R2 .
The jury wants to choose the value of that would maximize radius r2. Help the jury find the sought value of R2. Value R2 doesn ' t has the to is an integer.
Medal have a uniform thickness throughout the area, the thickness of the inner disk are the same as the thickness of the out ER ring.
Input
The first input line contains an integerNand a sequence of integers x1,? X2,?...,? xn . The second input line contains an integermand a sequence of integers y1,? Y2,?...,? Ym . The third input line contains an integerkand a sequence of integers z1,? Z2,?...,? Zk . The last line contains and integersAandB.
All numbers given in the input is positive and does not exceed 5000. Each of the three sequences contains distinct numbers. The numbers in the lines is separated by spaces.
Output
Print a single real number-the sought value r2 with absolute or relative error of in most 10 ?-? 6. It's guaranteed that solution that meets the problem requirements exists.
Sample Input
Input
3 1 2 31 23 3 2 11 2
Output
2.683281573000
Input
4 2 3 6 42 1 23 10 6 82 1
Output
2.267786838055
Hint
In the first sample the jury should choose the following values: r1?=?3, p1?=? 2, p2?=?1.
Test instructions
A kind of medal consists of inner circle and outer ring, outer ring radius is r1, density is P1, inner circle radius is r2, density is p2; a mass ratio of outer ring and inner circle is given (A/b)!
Give a series of r1,p1,p2! Choose the r1,p1,p2 from which the maximum R2 is required!
Ps:
The height of the inner circle and outer ring are the same, the formula! After simplification:
((r1^2-r2^2) *P1)/(R1^2*P2) = A/b;
Directly find the largest r1,p1, and the smallest P2;
The code is as follows:
#include <cstdio> #include <cmath>int main () { int n, m, K; Double R1, R2, p1, p2; while (~SCANF ("%d", &n)) { double tt; R1 = 0; for (int i = 0; i < n; i++) { scanf ("%lf", &tt); if (TT > R1) r1 = TT; } scanf ("%d", &m); P1 = 0; for (int i = 0; i < m; i++) { scanf ("%lf", &tt); if (TT > p1) p1 = tt; } scanf ("%d", &k); P2 = 5000+47; for (int i = 0; i < K; i++) { scanf ("%lf", &tt); if (TT < p2) p2 = tt; } int A, B; scanf ("%d%d", &a,&b); Double ans = sqrt ((r1*r1*p1*b)/(P1*b+p2*a)); printf ("%lf\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 215B Olympic medal (math AH)