hdu--4870 Rating(高斯消元,概率)

6 篇文章 0 订阅
3 篇文章 0 订阅

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

有一个人注册了两个账号,每次选取rating低的比赛,每次有p的概率rating涨50,1-p的概率rating降100,求有一个账号到1000分的比赛场数的期望。

f(0, 0) = f(0, 1) * p + f(0, 0) * q + 1; f(i, j)为状态为(i, j)时的期望(i <= j)(将21个可能的分数变成0~20,及0为0分,1为50分。。。。)

一共有210个状态,用高斯消元求解,求得的x[0]就是答案。(注意精度)

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

#define pb push_back
#define MP make_pair

const double eps = 1e-15;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 250;

double a[maxn][maxn], p, x[maxn];
int equ, var, n, used[maxn][maxn];

void Gauss(){
    int col, row, mx;
    for(col=0, row=0; col<var && row<equ; col++, row++){
        mx = row;
        for(int i=row+1; i<equ; i++)
            if(fabs(a[i][col]) - fabs(a[mx][col]) > eps) mx = i;
        if(fabs(a[mx][col]) < eps){row--; continue;}
        if(mx != row)
            for(int i=col; i<=var; i++)
                swap(a[mx][i], a[row][i]);
        for(int i=row+1; i<equ; i++){
            if(fabs(a[i][col]) < eps) continue;
            double t = a[i][col] / a[row][col];
            a[i][col] = 0.0;
            for(int j=col+1; j<=var; j++)
                a[i][j] -= t * a[row][j];
        }
    }
    for(int i=var-1; i>=0; i--){
        if(fabs(a[i][i]) < eps) continue;
        double temp = a[i][var];
        for(int j=i+1; j<var; j++)
            temp -= a[i][j] * x[j];
        x[i] = temp / a[i][i];
    }
    printf("%.6lf\n", x[0]);
}
void init(){
    int idx = 0;
    memset(used, -1, sizeof(used));
    for(int j=0; j<20; j++)
    for(int i=0; i<=j; i++)
        used[i][j] = idx++;
}
void init1(){
    memset(a, 0, sizeof(a));
    memset(x, 0, sizeof(x));
    equ = var = 210;
    for(int j=0; j<20; j++){
        for(int i=0; i<=j; i++){
            int k = used[i][j];
            a[k][k] = 1;
            a[k][210] = 1;
            int to = used[max(0, i - 2)][j];
            a[k][to] -= (1.0 - p);
            if(i == j) to = used[j][j + 1];
            else to = used[i + 1][j];
            a[k][to] -= p;
        }
    }
}
int main(){
    //freopen("out.txt", "w", stdout);
    init();
    while(cin >> p){
        init1();
        Gauss();
    }
    return 0;
}

还有一种厉害的递推公式是做法。。送上连接 http://www.cnblogs.com/chanme/p/3861766.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值