HDU 4870 Rating Gaussian eliminating element method

Source: Internet
Author: User

Links: http://acm.hdu.edu.cn/showproblem.php?pid=4870

Test instructions: With two accounts to participate in a game, the initial state of two accounts are 0 points, each game with a low score of the account to play. have p probability to win, the corresponding account score up 50 points, or the corresponding account score down 100 points, ask when there is an account score of 1000 time to participate in the number of mathematical expectations of the game.

Idea: During the game thought is a formula to push the problem, pushed for a long time no harvest.

I thought about it after the game. Read the report after the title. You know, every single one of these scores. The corresponding state is pushed by more than two states and is not pushed forward from backward to the situation can be solved by Gauss elimination. Status 0~ State 209 respectively represents the score for (0,0), (50,0) ... (950,950) to have an account score of 1000 for the mathematical expectation. E (x, y) =p (E (x1,y1) +1) + (1-p) (E (x2,y2) +1), (X1,y1) represents the score of the two accounts after the match, (X2,y2) represents the score of two accounts after the failure of the match.

State is not counted in the status (1000,?) It is because other states do not appear except (1000,950). and (1000,950) the state is only related to the state (950,950), and (950,950) does not get from (1000,950), 210 states no State is with (1000,?

Status related, so no processing is required.

Code:

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <map># Include <cstdlib> #include <queue> #include <stack> #include <vector> #include <ctype.h># Include <algorithm> #include <string> #include <set> #define PI acos ( -1.0) #define MAXN 210#define INF 0x7fffffff#define EPS 1e-8#define MOD 1000000009typedef long long ll;typedef unsigned long long ull;using namespace Std;do    Uble a[220][220],b[220];int all[25];d ouble gauss_elimination (int n) {int i,j,k,row;    Double maxp,t;                For (k=0, k<n; k++) {for (maxp=0,i=k; i<n; i++) if (Fabs (A[i][k]) >eps) {                MAXP=A[ROW=I][K];            Break        } if (Fabs (MAXP) <eps) return 0;            if (row!=k) {for (j=k; j<n; j + +) Swap (a[k][j],a[row][j]);        Swap (B[k],b[row]); } for (int j = 0; J < N; j + +) {if (k= = j) Continue;                if (Fabs (a[j][k) > EPS) {double x = a[j][k]/a[k][k];                for (int i = k; i < n; i++) {a[j][i]-= a[k][i] * x;            } B[j]-=b[k]*x; }}} return 1;}    int init () {all[0]=0;    for (int i=1; i<=21; i++) {all[i]=all[i-1]+i; } return 0;}    int main () {double p;    Init ();        while (~SCANF ("%lf", &p)) {memset (a,0,sizeof (a));        Memset (b,0,sizeof (b)); for (int i=0, i<20; i++) {for (int j=0; j<=i; J + +) {A[all[i]+j][all[i]+j                ]+=1;                B[all[i]+j]+=1;                A[all[i]+j][all[i]+max (j-2,0)]+= (p-1);                if (j+1<=i) a[all[i]+j][all[i]+j+1]+= (-P);                    else {if (i==19&&j==19) continue; else a[all[i]+j][all[j+1]+i]+= (-P);        }}} gauss_elimination (210);    printf ("%.6lf\n", b[0]/a[0][0]); } return 0;}


HDU 4870 Rating Gaussian eliminating element method

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.