HDU 4576 Simple probability + scrolling array dp (Tai hang)

Source: Internet
Author: User
Tags cmath

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4576

The pit is big, and the addition will time out;

1#include <cstdio>2#include <iostream>3#include <sstream>4#include <cmath>5#include <cstring>6#include <cstdlib>7#include <string>8#include <vector>9#include <map>Ten#include <Set> One#include <queue> A#include <stack> -#include <algorithm> - using namespacestd; the #definell Long Long - #define_cle (M, a) memset (M, A, sizeof (m)) - #defineRepu (I, A, b) for (int i = A; I < b; i++) - #defineREPD (I, A, b) for (int i = b; i >= A; i--) + #defineSFI (n) scanf ("%d", &n) - #defineSFL (n) scanf ("%i64d", &n) + #definePFI (n) printf ("%d\n", N) A #definePFL (n) printf ("%i64d\n", N) at #defineMAXN 1000005 - intN, L, M, R, D; - intt =0, MM; - Doubledp[2][205]; - intMain () - { in      while(~SCANF ("%d%d%d%d", &n, &m, &l, &r) && (n + m + L +R)) -     { tot =0; +Repu (I,0, n +1) dp[0][i] =0.0; -dp[0][1] =1.0; the         intC; *Repu (I,0, M) $         {Panax Notoginseng SFI (d); -             if(L = =1&& r = = N)Continue; thec = d/N; +MM = D-n *C; A             if(mm) the             { +t =!T; -Repu (J,1, n +1) $                 { $                     intLT, RT; -                     if((n + (j-mm)) >= n) lt = (n + (j-mm))-N; -                     ElseLt = (n + (J-mm)); the                     if((j + mm) >= n) rt = (j + mm)-N; -                     ElseRT = (J +mm);Wuyi                     if(LT = =0) LT =N; the                     if(RT = =0) RT =N; -DP[T][J] = (Dp[!t][lt] + dp[!t][rt])/2.0; Wu                     //cout<<j<< ":" <<dp[t][j]<<endl; -                 } About             } $         } -         DoubleAns =0.0; -         if(L = =1&& r = = N) ans =1.0; -         Else ARepu (i, L, R +1) ans + =Dp[t][i]; +printf"%.4lf\n", ans); the     } -     return 0; $}
AC
1#include <cstdio>2#include <iostream>3#include <sstream>4#include <cmath>5#include <cstring>6#include <cstdlib>7#include <string>8#include <vector>9#include <map>Ten#include <Set> One#include <queue> A#include <stack> -#include <algorithm> - using namespacestd; the #definell Long Long - #define_cle (M, a) memset (M, A, sizeof (m)) - #defineRepu (I, A, b) for (int i = A; I < b; i++) - #defineREPD (I, A, b) for (int i = b; i >= A; i--) + #defineSFI (n) scanf ("%d", &n) - #defineSFL (n) scanf ("%i64d", &n) + #definePFI (n) printf ("%d\n", N) A #definePFL (n) printf ("%i64d\n", N) at #defineMAXN 1000005 - intN, L, M, R, D; - intt =0, MM; - Doubledp[2][205]; - intMain () - { in      while(~SCANF ("%d%d%d%d", &n, &m, &l, &r) && (n + m + L +R)) -     { tot =0; +Repu (I,0, n +1) dp[0][i] =0.0; -dp[0][1] =1.0; the         intC; *Repu (I,0, M) $         {Panax Notoginseng SFI (d); -             if(L = =1&& r = = N)Continue; thec = d/N; +MM = D-n *C; A             if(mm) the             { +t =!T; -Repu (J,1, n +1) $                 { $                     intLT, RT; -Lt = (n + (j-mm))%N; -RT = (j + mm)%N; the //if ((n + (j-mm)) >= n) lt = (n + (j-mm))-N; - //Else Lt = (n + (j-mm));Wuyi //if ((j + mm) >= n) rt = (j + mm)-N; the //Else RT = (j + mm); -                     if(LT = =0) LT =N; Wu                     if(RT = =0) RT =N; -DP[T][J] = (Dp[!t][lt] + dp[!t][rt])/2.0; About                     //cout<<j<< ":" <<dp[t][j]<<endl; $                 } -             } -         } -         DoubleAns =0.0; A         if(L = =1&& r = = N) ans =1.0; +         Else theRepu (i, L, R +1) ans + =Dp[t][i]; -printf"%.4lf\n", ans); $     } the     return 0; the}
TLE

%uh use AH must, though do not know why

HDU 4576 Simple probability + scrolling array dp (Tai hang)

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.