Rating

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

Total Submission(s): 213 Accepted Submission(s): 126

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

一场比赛,赢了能够得50分,输了扣100分,分数会超过1000和不会小于0.有个人用2个账号,始终用分数低的号比赛。已知赢一场比赛的概率为p求打到1000分的场数的期望值。

1、能够用高斯消元,

令E(X,Y)为账号分数为x,y打到1000的数学期望。

则有:

E(X,Y)=PE(X1,Y1)+(1-P)E(X2,Y2)+1,X1,Y1是XY分数赢了的分数。X2,Y2相应是输了的分数。如果X>=Y,每次比赛用Y的账号,就会有210条方程。用mark数组标记XY分数相应的系数的索引。

代码:

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <cstring>
#include <map>
#include <string>
#include <queue>
using namespace std;
#define LL long long
#define ULL unsigned long long
//#define REP(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define INFLL (1LL)<<62
#define mset(a) memset(a,0,sizeof a)
#define FR(a) freopen(a,"r",stdin)
#define FW(a) freopen(a,"w",stdout)
#define PI 3.141592654
const LL MOD = 1000000007;
const int maxn=222;
const double eps=1e-9;
double a[maxn][maxn];
int mark[25][25];
int cnt;
double gauss()
{
int m=211;
int n=210;
for(int i=0;i<n;i++)
{
int k=i;
for(;k<n;++k)
if(fabs(a[k][i])>eps) break;
if(i!=k)
for(int j=0;j<=n;++j)
swap(a[i][j],a[k][j]);
for(int j=0;j<n;++j)
{
if(i==j) continue;
if(fabs(a[j][i])<eps) continue;
double x=a[j][i]/a[i][i];
for(k=i;k<m;++k)
a[j][k]-=a[i][k]*x;
}
}
return a[0][n]/a[0][0];
} void makeMat(double p)
{
mset(a);
int m=211;
int x=0,y=0;
for(y=0;y<20;++y){
for(x=0;x<y;++x)
{
int temp=mark[y][x];
a[temp][temp]=1;
a[temp][m-1]=1;
int temp2=mark[y][max(0,x-2)];
a[temp][temp2]-=1-p;
temp2=mark[y][x+1];
a[temp][temp2]-=p;
}
int t=mark[y][y];
a[t][t]=1;
a[t][m-1]=1;
int tt=mark[y][max(0,x-2)];
a[t][tt]-=1-p;
tt=mark[x+1][x];
a[t][tt]-=p;
}
} int main()
{
double p;
cnt=0;
mset(mark);
REP(i,0,20)
REP(j,0,i)
mark[i][j]=cnt++;
while (cin>>p)
{
makeMat(p);
printf("%.6lf\n",gauss());
}
}

2、用dp

首先离散化,由于每场比赛分数的变化都是50的倍数。令每场赢了得1分。输了扣2分。

dp[i]表示单场比赛从i分数提高到i+1的分数的期望值。

则有:dp[i]=p+(1-p)(dp[i-2]+dp[i-1]+dp[i]+1)

==>dp[i]=1/p+(1-p)/p*(dp[i-2]+dp[i-1]);dp[0]=1/p,dp[1]=1/p/p;

用ans[i][i]表示两个账号分数从0打到ii的期望,对于账号分数的上升,他们是交错上升的。意思是当他们分数一样的时候,前面的赢一分,当前面的赢了一分之后,下一场就后面的赢。所以仅仅须要维护ans[i+1][i] 和ans[i+1][i+1],且

ans[i+1][i]=ans[i][i]+dp[i],ans[i+1][i+1]=ans[i+1][i]+dp[i],

代码:

#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
double dp[22];
double ans[22][22]; int main()
{
double p;
while (cin>>p)
{
dp[0]=1/p;
dp[1]=1/p/p;
for(int i=2;i<20;++i)
dp[i] = 1+(1-p)/p*(dp[i-2]+dp[i-1]+1);
ans[0][0]=0;
for (int i=0;i<20;++i)
{
ans[i+1][i]=ans[i][i]+dp[i];
ans[i+1][i+1]=ans[i+1][i]+dp[i];
}
printf("%.6lf\n",ans[20][19]);
}
}

hdu4870 Rating (高斯消元或者dp)的更多相关文章

  1. BZOJ 2337: [HNOI2011]XOR和路径 [高斯消元 概率DP]

    2337: [HNOI2011]XOR和路径 题意:一个边权无向连通图,每次等概率走向相连的点,求1到n的边权期望异或和 这道题和之前做过的高斯消元解方程组DP的题目不一样的是要求期望异或和,期望之间 ...

  2. CF113D 高斯消元、dp

    题目链接 https://codeforces.com/contest/113/problem/D 思路 \(k[i]=\frac{1-p[i]}{ru[i]}\) f[i][j]表示经过i和j的次数 ...

  3. LightOJ 1151 - Snakes and Ladders 高斯消元+概率DP

    首先来个期望的论文,讲的非常好,里面也提到了使用线性方程组求解,尤其适用于有向图的期望问题. 算法合集之<浅析竞赛中一类数学期望问题的解决方法> http://www.lightoj.co ...

  4. hdu 4870 rating(高斯消元求期望)

    Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. Broken robot CodeForces - 24D (三对角矩阵简化高斯消元+概率dp)

    题意: 有一个N行M列的矩阵,机器人最初位于第i行和第j列.然后,机器人可以在每一步都转到另一个单元.目的是转到最底部(第N个)行.机器人可以停留在当前单元格处,向左移动,向右移动或移动到当前位置下方 ...

  6. [luogu2973]driving out the piggies 驱逐猪猡【高斯消元+概率DP】

    看到题面的那一刻,我是绝望的ORZ 图论加概率期望加好像不沾边的高斯消元???我人直接傻掉 还没学过概率期望的我果断向题解屈服了(然后还是傻掉了两节课来找线性方程.. Description 奶牛们建 ...

  7. Codeforces 446D - DZY Loves Games(高斯消元+期望 DP+矩阵快速幂)

    Codeforces 题目传送门 & 洛谷题目传送门 神仙题,%%% 首先考虑所有格子都是陷阱格的情况,那显然就是一个矩阵快速幂,具体来说,设 \(f_{i,j}\) 表示走了 \(i\) 步 ...

  8. BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡 [高斯消元 概率DP]

    1778: [Usaco2010 Hol]Dotp 驱逐猪猡 题意:一个炸弹从1出发p/q的概率爆炸,否则等概率走向相邻的点.求在每个点爆炸的概率 高斯消元求不爆炸到达每个点的概率,然后在一个点爆炸就 ...

  9. BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡(高斯消元+期望dp)

    传送门 解题思路 设\(f(x)\)表示到\(x\)这个点的期望次数,那么转移方程为\(f(x)=\sum\frac{f(u)*(1 - \frac{p}{q})}{deg(u)}\),其中\(u\) ...

随机推荐

  1. P1290sk抓螃蟹

    背景 sk,zdq想在hzy生日之际送hzy几只螃蟹吃... 描述 现有n只螃蟹,每个在一个二维作标上,保证没有任何两个螃蟹重合.sk伸手抓螃蟹 了,他怕螃蟹的攻击,当他捉一只螃蟹时,其他螃蟹都朝这只 ...

  2. B1965 [Ahoi2005]SHUFFLE 洗牌 数论

    这个题的规律很好找,就是奇数直接除二,偶数除二加n/2.把这个规律整理一下就是(x * 2) % (n + 1),然后就直接求逆元就行了.一直30分的原因是qpow函数传参的时候用的int,然而变量是 ...

  3. 第8章 MyBatis简介

    # 创建一个名称为mybatis的数据库 CREATE DATABASE mybatis; # 使用名称为mybatis的数据库 USE mybatis; # 创建一个tb_user表,有id.nam ...

  4. LINUX/UNIX找回删除的文件

    当Linux计算机受到入侵时,常见的情况是日志文件被删除,以掩盖攻击者的踪迹.管理错误也可能导致意外删除重要的文件,比如在清理旧日志时,意外地删除了数据库的活动事务日志.有时可以通过lsof来恢复这些 ...

  5. [Swift]注册并购买加入Apple开发者计划。提示: “你的支付授权失败。请核对你的信息并重试,或尝试其他支付方式。请联系你的银行”

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. typescript 基本数据类型

    1.boolen 布尔类型 let boolen1: boolen = false; 2.number 数字类型 let num1: number = 0b110;//二进制 let num2: nu ...

  7. VS中的路径宏

    说明$(RemoteMachine)设置为“调试”属性页上“远程计算机”属性的值.有关更多信息,请参见更改用于 C/C++ 调试配置的项目设置.$(References)以分号分隔的引用列表被添加到项 ...

  8. 查找DLL,并复制出来

    Subst b: %windir%\assembly 执行完后,会发现硬盘分区多了个B盘,打开后看到了所有assembly下的DLL,于是在这里就搜到了Microsoft.ReportViewer.P ...

  9. 使用新的CSS类型对象模型

    el.attributeStyleMap.set('padding', CSS.px(42)); const padding = el.attributeStyleMap.get('padding') ...

  10. HTML与CCS(十一)

    1.1 HTML介绍 1.1.1 Web服务本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) s ...