Show all threads Hide all threads Show all messages Hide all messages | The most stupid solution | andreyDagger`~ | 1621. Definite Integral | 23 Mar 2024 21:40 | 1 | Just run Simpson's method, you will only need to find suitable "a", "b" and "N" parameters, but it can be done easily with trial and error method | Two solutions | Teacher30 (Burunduk1) | 1621. Definite Integral | 16 Feb 2020 23:45 | 3 | Solution #1: AC in 0.8 sec Just calculate sum using Gauss's method. Int[-1..1] f(x)dx ~= (5*f(-sqrt(3/5)) + 8*f(0) + 5*f(+sqrt(3/5))) / 9 Number of parts, N = (int)7e6 Length of part number i = (1e-4)*koef^i, where koef = 1 + x/N. Try some different x = 0.1 ... 10, and get AC =) Solution #2: WA 11 on MSVC or AC on Java, Pascal, GNU C++ http://en.wikipedia.org/wiki/Residue_theorem says that we have to find all complex roots of the polynom. I do not like exact formulas for degree 3 and 4. There is numerical way to find all complex roots for any degree of polynom. Just take point z = (0,0) and shift it to any direction in such a way that |P(z+shift)| < |P(z)|. Shift it while |P(z)| > eps. Now z is a root. This method works not only for polynoms, it works even for arbitrary "holomorphic function" (see Complex Analysis). Prove is smth like this http://en.wikipedia.org/wiki/Maximum_modulus_principle The only thing that I need now -- to calculate f(z) for any complex z. And using only "double" of Microsoft Visual C++ I can't. I have no enough precision and get WA 11 =( Using BigDecimal (java), extended (pascal) or long double (GNU C/C++) this method gets AC (the task is from Petrozavodsk, so I have original tests). P.S. 2 Admins: Ну сколько можно добавлять задачки с контестов, где у С++ программистов был под рукой long double, и это было важно. Даешь GNU C/C++! Edited by author 27.10.2012 08:08I found many other ways. 1)Monte Carlo - slow for this problem 2)Separation of real and complex roots. Can be used to solve this problem. Binary search for Re(z)=alfa, Re(z)=beta, Im(z)=gamma, Im(z)=delta Березин И.С., Жидков Н.П. Методы вычислений, Т.2. М.: ГИФМЛ, 1959. 3)Ferrari method. Куликов Л.Я. Алгебра и теория чисел 4)Barstow method. It's numeric iterative method. Саманчук_билеты_с_ответами.pdf Численные методы I use combination from 3): binary search for yo then formulas Edited by author 12.08.2018 21:04 https://en.wikipedia.org/wiki/Adaptive_quadrature with Gaussian method to estimate value of definite integral: approx_integrate(Func f, long double l, long double r) { long double A = sqrtl(3.0l/5.0l)/2, x1=0.5-A, x2 = 0.5+A; return (5*f(l*x1 + r*x2) + 8*f((l+r)/2) + 5*f(l*x2+r*x1))/18 * (r-l); } AC in 0.015. That is, you don't even need to think to solve this problem. Edited by author 16.02.2020 23:48 | Test 11 | mouse_wireless2 | 1621. Definite Integral | 15 Jan 2018 20:09 | 1 | Test 11 mouse_wireless2 15 Jan 2018 20:09 If you're struggling with test 11, the test is: 1 0 1000000 -2000 1 Exact (up to 1e-14) answer is 0.00628318530714 If your solution passes this, it will most likely pass all tests :) | Hint for WA11 | Mickkie | 1621. Definite Integral | 19 Oct 2017 13:02 | 2 | You must deal with e-9 precision such test like 999999 100099 1000000 0 1 the solution is 3.1423994906657376×10−6 Good Luck :) must use long double .... | How to solve? | kilik | 1621. Definite Integral | 9 Jun 2017 04:40 | 2 | I use ferrari method to find roots. Then i got next equation 1/((x-a)*(x-b)*(x-c)*(x-d)), where a,b,c,d -roots of equation. How to calculate such an integral??? If someone can answer here or kilik94@yandex.ru, i would be very grateful! i'm not exactly sure of the solution but i think you could use rezidue theorem and solve the complex integral | Can someone give me any tips for test #11 pls | HeypaBHoBeceH | 1621. Definite Integral | 31 Jan 2012 13:48 | 7 | First I thought it was precision but now I don't know anymore. I thought i would never post a thread like this one but... this is a part of my code, f_x() is P(x): left1 = left2 = f_x(0); for(x = 1e-3 ; x < 6000 ; x += 1e-3) { y1 = f_x(+ x); y2 = f_x(- x); ans += ((((left1 + y1)/left1)/y1)) + ((((y2 + left2)/y2)/left2)); left1 = y1; left2 = y2; } ans *= 0.5*(1e-3); Try to use dx and limits which can be represented in binary form exactly (e.g. 1/1024.0 instead of 1e-3) appreciate the tip, but still WA11... Why are you using plus-minus 6000 as limits? 1/P(x) could have its maximum as far as x = 10^6 and a bit further. Edited by author 06.12.2008 22:36 nvm, Accepted! Edited by author 02.06.2009 14:16 Thank you a lot, I AC!!!!!!!!!!!!!! | about test 2 | cjqcjq | 1621. Definite Integral | 18 Aug 2009 04:55 | 3 | I got wa at test 2 Can you give me some hints about that test? Thank you! I have WA 2 too. I used Ferrari's method to find the roots of polynomial and Gaussian elimination. My prog passed all my tests but it got WA 2 here. Can anybody help me? Oh God... My problem was evil precision. I've written my solution with JAVA's BigDecimal and got AC. Edited by author 18.08.2009 04:56 Edited by author 18.08.2009 04:56 | GCD (P(x), P'(x)) = const ? | Anisimov Dmitry | 1621. Definite Integral | 22 Jul 2009 15:50 | 5 | As I understand, this conditions means P(x) has only simple roots. I tried various solutions to find roots and have got an impression this is not true. I think you have problem with precision. It is very hard to solve this problem with numeric solver, try to calculate exact solution True. Reimplementing same thing for 64-bit precision (in Pascal) works okay. I succeed with numeric Barstow method and avoid monkey Ferrari formulas. Because evil Olympiad precision 1.e-09 I was forced to implement Barstow above BigGecimal in Java. Who want good tests use MathCad. It's integration in case rather accurate. For those who inerested I write Barstow method from my prog: shorten- also my method for cutting off long BigDecimals public static BigDecimal Barstow(BigDecimal a[], int N, BigDecimal u0, BigDecimal v0, BigDecimal eps, int MaxIter, int MaxLen)[]
{ BigDecimal u, v; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = null; int k, n,faza; u = u0; v = v0; BigDecimal[] b = new BigDecimal[N+1]; BigDecimal[] c = new BigDecimal[N+1]; BigDecimal rez[] = new BigDecimal[N+3]; BigDecimal d, s, q,h; BigDecimal Z = new BigDecimal("0.0"); BigDecimal bb1, bb2; h = new BigDecimal("0.0000000000000000000000000000000000000001"); faza = 0; for (k = 0; k <= MaxIter; k++) {
for (n = 0; n <= N; n++) { if (n < 1) bb1 = Z; else bb1 = b[n - 1]; if (n < 2) bb2 = Z; else bb2 = b[n - 2]; b[n] = shorten(a[n].add(bb1.multiply(u)).add(bb2.multiply(v)), MaxLen); } for (n = 0; n <= N - 1; n++) { if (n < 1) bb1 = Z; else bb1 = c[n - 1]; if (n < 2) bb2 = Z; else bb2 = c[n - 2]; c[n] = shorten((b[n].add(bb1.multiply(u))).add(bb2.multiply(v)), MaxLen); } d = shorten(((b[N].multiply(c[N - 3])).subtract(b[N - 1].multiply(c[N - 2]))), MaxLen); q = shorten((c[N - 2].multiply(c[N - 2])).subtract(c[N - 1].multiply(c[N - 3])), MaxLen); d = shorten(d.divide(q, BigDecimal.ROUND_FLOOR), MaxLen); s = shorten(((b[N - 1].multiply(c[N - 1])).subtract(b[N].multiply(c[N - 2]))), MaxLen); s = shorten(s.divide(q, BigDecimal.ROUND_FLOOR), MaxLen); if ((d.abs().compareTo(eps) < 0) && (s.abs().compareTo(eps) < 0)) { if (faza == 0) { faza = 1; MaxLen = MaxLen * 4; eps = eps.multiply(h); } else break; } u = u.add(d); v = v.add(s); k = k; } rez[0] = u; rez[1] = v; for (n = 0; n <= N; n++) rez[n + 2] = b[n]; return rez; }
Edited by author 27.09.2008 15:32 I implemented Barstow in C++ as svr suggested but wa11 ... Is there any possibility that good initial guesses obtain a result up to desired precision using Barstow without long arithmetics ? | Compiler hints: if you're going to use complex numbers in C++ | Anisimov Dmitry | 1621. Definite Integral | 18 Aug 2008 21:14 | 1 | #include <complex> using namespace std; complex<double> X; | How to solve this problem? | Al.Cash | 1621. Definite Integral | 18 Aug 2008 21:13 | 2 | I've found a simple formula for this integral, but it uses p1, q1, p2, q2 such that P(x)= a4 ( x^2 + p1 · x + q1) · ( x^2 + p2 · x + q2). These values are always real, but I don't know how to find them. Maybe there is a solution which doesn't use them? Of course there is. 1). Use Ferrari method to find roots. 2). Use numerical method to find roots. 3). Use generic numerical methods without finding roots. All are not-so-easy to implement. |
|
|