hdu 4870 Rating(高斯消元求期望)

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

题意:有两个号,初始分数都是0,每次选一个分数较小的打比赛,如果分数一样任选一个,有p的概率涨50分,最高为1000分,有1-p的概率跌100分,最低为0分。问有一个号涨到1000需要打比赛的次数的期望。

令(x, y)表示高分为x,低分为y的状态(x >= y),E(x, y)表示从(x, y)到达(1000, ?)的比赛场数期望。容易得到E(x, y) = P * E(x1, y1) + (1 - P) * E(x2, y2) + 1,其中,(x1, y1)表示rating上升后的状态,(x2, y2)表示rating下降后的状态。每50分一个状态,共有210个状态。

移项后得E(x, y)
-P * E(x1, y1) - (1 - P) * E(x2, y2) = 1,共有210个这样的方程组。高斯消元求解,x[0]代表E(0,0)这个状态到目标状态的期望。

注意精度。

#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;
}

时间: 2024-10-25 21:18:31

hdu 4870 Rating(高斯消元求期望)的相关文章

hdu 2262 高斯消元求期望

Where is the canteen Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1070    Accepted Submission(s): 298 Problem Description After a long drastic struggle with himself, LL decide to go for some

hdu 3992 AC自动机上的高斯消元求期望

Crazy Typewriter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 391    Accepted Submission(s): 109 Problem Description There was a crazy typewriter before. When the writer is not very sober, it

hdu 4418 高斯消元求期望

Time travel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1480    Accepted Submission(s): 327 Problem Description Agent K is one of the greatest agents in a secret organization called Men in B

HDU4870_Rating_双号从零单排_高斯消元求期望

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4870 原题: Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 654    Accepted Submission(s): 415 Special Judge Problem Description A little gir

[ACM] hdu 2262 Where is the canteen (高斯消元求期望)

Where is the canteen Problem Description After a long drastic struggle with himself, LL decide to go for some snack at last. But when steping out of the dormitory, he found a serious problem : he can't remember where is the canteen... Even worse is t

uva 10828 高斯消元求数学期望

Back to Kernighan-RitchieInput: Standard Input Output: Standard Output You must have heard the name of Kernighan and Ritchie, the authors of The C Programming Language. While coding in C, we use different control statements and loops, such as, if-the

hdu 1071 The area 高斯消元求二次函数+辛普森积分

构造系数矩阵,高斯消元求解二次函数,然后两点式求直线函数,带入辛普森积分法无脑AC... #include<cstdio> #include<queue> #include<algorithm> #include<cstring> #include<vector> #include<cmath> using namespace std; struct node { double x,y; }p[4]; double g[10][10]

HDU 3949 XOR 高斯消元

题目大意:给定一个数组,求这些数组通过异或能得到的数中的第k小是多少 首先高斯消元求出线性基,然后将k按照二进制拆分即可 注意当高斯消元结束后若末尾有0则第1小是0 特判一下然后k-- 然后HDU输出long long是用%I64d 无论C艹还是G艹都是 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define M 10100 using namespa

高斯消元 求整数解模版

#include <iostream> #include <string.h> #include <cmath> using namespace std; const int maxn = 105; int equ, var; // 有equ个方程,var个变元.增广阵行数为equ, 分别为0到equ - 1,列数为var + 1,分别为0到var. int a[maxn][maxn]; int x[maxn]; // 解集. bool free_x[maxn]; //