|
|
If you are solving using formula, there are some corner cases. IN 0 0 0 0 OUT 0 IN 17 0 0 17 OUT 17 And just some random test. IN 7 9 6 8 OUT 15.165177459575631 Можно сдать тернарным поиском на Python 3.4 с параметрами : количество итераций -- 100 максимальное А и максимальное B -- 10**18 Did anybody solve it with numerical algo (local optimization)? I think using Java is best way. Firstly I used parameter MaxLen=100 for BigDecimal and Wa3. Maxlen:=200 and Ac. Thus to garantie given precision in answer 1e-9 is difficult without long numbers. 2 svr: I've accepted it with usual double in C++ I and begginers must be caution. A~1e6; A'A~1e12, t^2-Qt+Z=0;Q,Z~1e24;D=Q^2-4*Z~1e+48 how take t with 1e-9 in 16 digits!? My formula uses only numbers about 10^12 ;) If you have valid analytic solution to the problem, numbers wouldn't make much difficulty, or so it seems to me. i used ternary search Edited by author 22.06.2010 13:54 I solved it using numerical optimization. I've got AC with a code having only 20 lines. Why A1=1 B1=2 A2=2 B2=4 The answer is 5? Please tell me.Thank you. #include<iostream> #include<iomanip> #include<cmath> int a1,b1,a2,b2; double func(double x); int main() { using std::cin; using std::cout; using std::endl; cin >> a1 >> b1 >> a2 >> b2; double delta = 1e-4; double head = 1e-4; double tail = 1000000+head; while(1) { double mid = 0.5*(head + tail); double cur = func(mid); double up = func(mid+delta); double down = func(mid - delta); if((cur-up)*(cur-down)>=0) { cout.setf(std::ios::fixed|std::ios::showpoint); cout.precision(9); cout << cur << endl; return 0; }else { if(up>=cur) { head = mid + delta; } else { tail = mid - delta; } } } } double func(double x) { return sqrt((a1+b1*x)*(a1+b1*x)/(1 + x*x) + (a2+b2*x)*(a2+b2*x) / (1 + x*x)); } try lond double for func & x, and long long for a1,a2,b1,b2. i don't sure, but it must help... I find maximum of the maximal influence of elixir by formula: Math.sqrt((b1 * b1 + b2 * b2 + a1 * a1 + a2 * a2 +Math.sqrt(a1 * a1 * a1 * a1 + a2 * a2 * a2 * a2 + 8 * a1 * a2 * b1 * b2 - 2 * a2 * a2 * (b1 * b1 - b2 * b2) + 2 * a1 * a1 * (a2 * a2 + b1 * b1 - b2 * b2) + (b1 * b1 + b2 * b2) * (b1 * b1 + b2 * b2))) / 2) ...and get wa. What's wrong? sorry, too many letters P.S. No comments Don't you think, that 10^24 doesn't fit into double? =/ with your formula, you should use BigDecimal... Edited by author 18.10.2008 15:59 long long type give me WA10! When I replaced the long long to long double I get AC You are right! It's importent not magnitude 10^24 but condition number of the problem and number of right digits in result:7+9=16<18 9 fractional digits. but in case 1, output is 5.4649857042190426504511884932842 I don't know, but, however, this is a good question :D Hint: the answer is twice irrational. Don't "HaHa!!".I have WA#1,but my output such as in output in examples((( Naskol'ko ya mogu ponyat', dlya vychislenya kachestva neobhodimo znat' A i B. No... Oni tam vrode ne dany... No comments. Please, use English As I can understand, for counting quantity we need A and B ... But they ain't given here! |
|
|