HDU 3076 ssworld vs DDD probability DP, infinite series, OJ error question difficulty: 2

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3076

An incredible question: in short, the smaller the blood volume, the higher the odds, so the two exchanged the blood volume during reading.

Obviously, the winning rate and negative rate of each round are fixed. Therefore, set PSC as the winning rate, pls as the negative rate, and peq as the flat rate,

The winning rate and negative rate in each game can be determined,

The odds and negatives in a stage with results are an infinite series.

PSC (new) = 1 * PSC + peq * PSC ....... = Lim (n-> positive infinity) (1-peq ^ N) * PSC/(1-peq) = PSC/(1-peq)

PLS (new) = 1 * PLS + peq * PLS ....... = Lim (n-> positive infinity) (1-peq ^ N) * pls/(1-peq) = pls/(1-peq)

Set P [I] [J] to the probability that HP of A is I, and HP of B is J

Obviously, the transfer formula is:

When I> 0, j> 0

P [I-1] [J] + = P [I] [J] * PLS (new)

P [I] [J-1] + = P [I] [J] * PSC (new)

 

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>using namespace std;const int maxn=2e3+3;double p[maxn];double pp[2][6];double psc,pls,peq;int a,b;double ans;void calc(){    psc=pls=peq=0;    ans=0;    memset(p,0,sizeof p);    for(int i=0;i<6;i++){        for(int j=0;j<6;j++){            if(i==j)peq+=pp[0][i]*pp[1][j];            else if(i<j)pls+=pp[0][i]*pp[1][j];            else psc+=pp[0][i]*pp[1][j];        }    }    if(peq!=1){        psc/=(1-peq);        pls/=(1-peq);    }    p[b]=1;    for(int i=a;i>0;i--){        for(int j=b;j>0;j--){            p[j-1]+=p[j]*psc;        }        ans+=p[1]*psc;        for(int j=b;j>0;j--){            p[j]*=pls;        }    }}int main(){    while(scanf("%d%d",&b,&a)==2){        for(int i=0;i<6;i++)scanf("%lf",pp[0]+i);        for(int i=0;i<6;i++)scanf("%lf",pp[1]+i);        calc();        printf("%.6f\n",ans);    }    return 0;}

 

HDU 3076 ssworld vs DDD probability DP, infinite series, OJ error question difficulty: 2

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.