hdu 4870 Rating(概率DP&高数消元)

Rating

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 714    Accepted Submission(s): 452

Special Judge

Problem Description

A little girl loves programming competition very much. Recently, she has found a new kind of programming competition named "TopTopTopCoder". Every user who has registered in "TopTopTopCoder" system will have a rating, and the initial
value of rating equals to zero. After the user participates in the contest held by "TopTopTopCoder", her/his rating will be updated depending on her/his rank. Supposing that her/his current rating is X, if her/his rank is between on 1-200 after contest, her/his
rating will be min(X+50,1000). Her/His rating will be max(X-100,0) otherwise. To reach 1000 points as soon as possible, this little girl registered two accounts. She uses the account with less rating in each contest. The possibility of her rank between on
1 - 200 is P for every contest. Can you tell her how many contests she needs to participate in to make one of her account ratings reach 1000 points?

Input

There are several test cases. Each test case is a single line containing a float number P (0.3 <= P <= 1.0). The meaning of P is described above.

Output

You should output a float number for each test case, indicating the expected count of contest she needs to participate in. This problem is special judged. The relative error less than 1e-5 will be accepted.

Sample Input

1.000000
0.814700

Sample Output

39.000000
82.181160

Author

FZU

Source

2014 Multi-University Training Contest 1

Recommend

We have carefully selected several similar problems for you:  4896 4895 4894 4892 4891

题意:

一个人打cf。规则是如果他排名前200就加50分最高加到1000.否侧减100分。最低到0分。现在告诉你他一场比赛前200的概率p.然后他申请了两个账号初始分都为0.每次比赛他会用分数低的那个账号低的那个账号打。现在问你他要上1000.有一个账号上就行了。需要参加比赛场数的期望。

思路:

由于加减分都是50的倍数。所以分数可以用[0,20]表示。没次可以减2分或加1分。用dp[i][j]表示分数高的账号分数为i。分数低的账号分数为j然后有一个账号上1000的概率。

那么dp[i][j]=p*(dp[i][j+1]+1)+(1-p)*(dp[i][j-2]+1)   i>j。如果j+1大于i就换成dp[j+1][i]。如果j-2小于0就换成dp[i][0]。然后对每个dp[i][j]编号。建立方程。然后高斯消元。

详细见代码:

#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=1e-11;
const int maxn=100010;
typedef long long ll;
int cnt,mp[50][50];
double mat[310][310];
bool gauss()
{
    int row,i,j,id;
    double maxx,var;
    for(row=0;row<cnt;row++)
    {
        maxx=fabs(mat[row][row]);
        id=row;
        for(i=row+1;i<cnt;i++)//mat[i][cnt]为常数项
        {
            if(fabs(mat[i][row])>maxx)
            {
                maxx=fabs(mat[i][row]);
                id=i;
            }
        }
        if(maxx<eps)
            return false;
        if(id!=row)
        {
            for(i=row;i<=cnt;i++)
                swap(mat[row][i],mat[id][i]);
        }
        for(i=row+1;i<cnt;i++)
        {
            if(fabs(mat[i][row])<eps)
                continue;
            var=mat[i][row]/mat[row][row];
            for(j=row;j<=cnt;j++)
                mat[i][j]-=mat[row][j]*var;
        }
    }
    for(i=cnt-1;i>=0;i--)
    {
        for(j=i+1;j<cnt;j++)
            mat[i][cnt]-=mat[i][j]*mat[j][j];
        mat[i][i]=mat[i][cnt]/mat[i][i];
    }
    return true;
}
int main()
{
    int i,j,ptr,base,pp,a,b,c;
    double p;

    for(i=0;i<=20;i++)
        for(j=0,base=i*(i+1)/2;j<=i;j++)
            mp[i][j]=base+j;
    cnt=231;
    while(~scanf("%lf",&p))
    {
        ptr=0;
        memset(mat,0,sizeof mat);
        for(i=0;i<=20;i++)
        {
            for(j=0;j<=i;j++)
            {
                if(i==20)
                {
                    pp=mp[i][j];
                    mat[ptr][pp]=1;
                    mat[ptr++][cnt]=0;
                    continue;
                }
                a=max(i,j+1);
                b=min(i,j+1);
                c=max(0,j-2);
                mat[ptr][cnt]=1;
                pp=mp[i][j];
                mat[ptr][pp]+=1;
                pp=mp[a][b];
                mat[ptr][pp]+=-p;
                pp=mp[i][c];
                mat[ptr++][pp]+=p-1;
            }
        }
        gauss();
        printf("%.8lf\n",mat[0][0]);
    }
    return 0;
}

hdu 4870 Rating(概率DP&高数消元)

时间: 2024-10-04 13:39:04

hdu 4870 Rating(概率DP&高数消元)的相关文章

HDU 4870 Rating 概率DP

Rating Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4870 Description A little girl loves programming competition very much. Recently, she has found a new kind of programming competition named

2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)

题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的那个去做,问她最终有一个账号达到1000分需要做的比赛的次数的期望值. 思路 :可以直接用公式推出来用DP做,也可以列出210个方程组用高斯消元去做. (1)DP1:离散化.因为50,100,1000都是50的倍数,所以就看作1,2,20.这样做起来比较方便. 定义dp[i]为从 i 分数到达i+1

hdu 4870 Rating(可能性DP&amp;amp;高数消除)

Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 714    Accepted Submission(s): 452 Special Judge Problem Description A little girl loves programming competition very much. Recently, she

【BZOJ 2337】 2337: [HNOI2011]XOR和路径(概率DP、高斯消元)

2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1170  Solved: 683 Description Input Output Sample Input Sample Output HINT Source Day2 [分析] 这题终于自己打出来了高斯消元.没有对比代码了... 很心酸啊..调试的时候是完全没有方向的,高斯消元还要自己一步步列式子然后消元解..[为什么错都不知道有时候 这题显然是不能

HDU 4870 Rating(高斯消元 )

HDU 4870   Rating 这是前几天多校的题目,高了好久突然听旁边的大神推出来说是可以用高斯消元,一直喊着赶快敲模板,对于从来没有接触过高斯消元的我来说根本就是一头雾水,无赖之下这几天做DP,正好又做到了这个题,没办法得从头开始看,后来在网上找了别人的高斯消元的模板后发现其实也还是很好理解,就是先构造一个增广矩阵,然后化行阶梯形,最后迭代求解 首先有一个介绍高斯消元感觉过于详细的博客http://blog.csdn.net/tsaid/article/details/7329301 首

HDU 4870 Rating(概率、期望、推公式) &amp;&amp; ZOJ 3415 Zhou Yu

其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒)四五次才上来写这份有抄袭嫌疑的题解... 这2题很类似,多校的rating相当于强化版,不过原理都一样.好像是可以用高斯消元做,但我不会.默默推公式了. 公式推导参考http://www.cnblogs.com/chanme/p/3861766.html#2993306 http://www.cn

HDU 4870 Rating(高斯消元)

HDU 4870 Rating 题目链接 题意:一个人注册两个账号,初始rating都是0,他每次拿低分的那个号去打比赛,赢了加50分,输了扣100分,胜率为p,他会打到直到一个号有1000分为止,问比赛场次的期望 思路:f(i, j)表示i >= j,第一个号i分,第二个号j分时候,达到目标的期望,那么可以列出转移为f(i, j) = p f(i', j') + (1 - p) f(i'' + j'') + 1 f(i', j')对应的是赢了加分的状态,f(i'', j'')对应输的扣分的状态

hdu 4870 Rating

Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 414    Accepted Submission(s): 261 Special Judge Problem Description A little girl loves programming competition very much. Recently, she

HDU 4035Maze(概率DP)

HDU 4035   Maze 体会到了状态转移,化简方程的重要性 题解转自http://blog.csdn.net/morgan_xww/article/details/6776947 /** dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点1处(概率为ki) 2.找到出口,走出迷宫 (概率为ei) 3.和该点相连有m条边,随机走一条 求:走出迷宫所要走的边数的期望值. 设 E[i]表示