HDU 4870 rating)

Source: Internet
Author: User

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


Question: There are two numbers, and the initial score is 0. Each time you choose a game with a small score, if you choose one with the same score, the probability of a P score increases by 50 points, and the maximum score is 1000 points, A probability of 1-P drops by 100,The minimum value is 0.. I would like to ask you the expected number of times you want to play the game when the number reaches 1000.


(X,Y) indicates that the high score is X, and the low score is Y (x> =Y), E (X,Y) indicates from (X,Y) reach (1000,?) Expected number of matches. E (X,Y)=P*E (x1,Y1)+(1-P)*E (X2,Y2)+1, where, (x1,Y1) indicates the status after rating rises. (X2,Y2) indicates the status after rating drops. Every 50 minutes, There are 210 statuses.

E (X,Y)-P*E (x1,Y1 )-(1-P)*E (X2,Y2) =1. There are 210 such equations. X [0] indicates the expectation that E (0, 0) is returned to the target State.

Pay attention to precision.


#include <stdio.h>#include <iostream>#include <map>#include <set>#include <stack>#include <vector>#include <math.h>#include <string.h>#include <queue>#include <string>#include <stdlib.h>#include <algorithm>#define LL long long#define _LL __int64#define eps 1e-12#define PI acos(-1.0)using namespace std;const int maxn = 231;double a[235][235],p;int equ,var;double x[235];int flag[235][235];int cnt;double Gauss(){    int row,col,max_r;    int i,j;    row = col = 0;    while(row < equ && col < var)    {        max_r = row;        for(i = row+1; i < equ; i++)            if(fabs(a[i][col])-fabs(a[max_r][col]) > eps)                max_r = i;        if(max_r != row)        {            for(j = col; j <= var; j++)                swap(a[row][j],a[max_r][j]);        }        if(fabs(a[row][col]) < eps)        {            col++;            continue;        }        for(i = row+1; i < equ; i++)        {            if(fabs(a[i][col]) > eps)            {                double t = a[i][col]/a[row][col];                a[i][col] = 0.0;                for(j = col+1; j <= var; j++)                    a[i][j] -= a[row][j]*t;            }        }        row++;        col++;    }    for(i = equ-1; i >= 0; i--)    {        if(fabs(a[i][i]) < eps) continue;        double tmp = a[i][var];        for(j = i+1; j < var; j++)            tmp -= a[i][j]*x[j];        x[i] = tmp/a[i][i];    }    return x[0];}int main(){    cnt = 0;    memset(flag,-1,sizeof(flag));    for(int i = 0; i < 20; i++)    {        for(int j = 0; j <= i; j++)            flag[i][j] = cnt++;    }    while(~scanf("%lf",&p))    {        equ = var = 210;        int x;        memset(a,0,sizeof(a));        for(int i = 0; i < 20; i++)        {            for(int j = 0; j < i; j++)            {                x = flag[i][j];                a[x][x] = 1;                a[x][210] = 1;                a[x][flag[i][max(0,j-2)]] -= (1-p);                a[x][flag[i][j+1]] -= p;            }            x = flag[i][i];            a[x][x] = 1;            a[x][210] = 1;            a[x][flag[i][max(0,i-2)]] -= (1-p);            a[x][flag[i+1][i]] -= p;        }        printf("%.6lf\n", Gauss());    }    return 0;}



HDU 4870 rating)

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.