[HDU4652] Dice

扔一个有m个面的骰子,每个面有一个数字,这些数字互不相同,求连续扔到n个数相同的期望步数或连续扔到n个数不同的期望步数

相同的:

  E[i]表示已经有i连续个相同,到达目标的期望步数

  E[i]=E[i+1]/m+(1-1/m)E[1].................... 1

  E[i+1]=E[i+2]/m+(1-1/m)E[1]................ 2

  1-2得 E[i]-E[i+1]=(E[i+1]+E[i+2])/m

  设s[i]=E[i]-E[i+1],

  则s[0]=E[0]-E[1]=1,s[i+1]=m*s[i],ans=sigma(s[i])(0<=i<n)  

不同的:

  E[i]表示已经有i连续个不同,到达目标的期望步数

  E[i]=simga(E[j])/m+((m-i)/m)E[i+1],(1<=j<=i).................. 1

  E[i+1]=sigma(E[j])/m+((m-i-1)/m)E[i+2],(1<=j<=i+1)....... 2

  1-2得 E[i]-E[i+1]=(m-i-1)/m*(E[i+1]-E[i+2])

  设s[i]=E[i]-E[i+1],

  则s[0]=E[0]-E[1]=1,s[i+1]=m/(m-i-1)s[i],ans=sigma(s[i])(0<=i<n)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define maxn 1000005
 4 int T,op,n;
 5 double m,s[maxn];
 6 void solve0(){
 7     s[0]=1;
 8     double ans=s[0];
 9     for(int i=0;i<n-1;i++)
10         s[i+1]=s[i]*m,ans+=s[i+1];
11     printf("%.9lf\n",ans);
12 }
13 void solve1(){
14     s[0]=1;
15     double ans=s[0];
16     for(int i=0;i<n-1;i++)
17         s[i+1]=m/(m-i-1)*s[i],ans+=s[i+1];
18     printf("%.9lf\n",ans);
19 }
20 int main(){
21     scanf("%d",&T);
22     while(T--){
23         scanf("%d%lf%d",&op,&m,&n);
24         if(op==0)solve0();
25         else solve1();
26     }
27     return 0;
28 }

  

时间: 2024-10-10 04:59:50

[HDU4652] Dice的相关文章

ACM学习历程—HDU 5012 Dice(ACM西安网赛)(bfs)

Problem Description There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a1.a2,a3,a4,a5,a6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A.

HDOJ 5012 Dice

BFS爆搜 Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 284    Accepted Submission(s): 166 Problem Description There are 2 special dices on the table. On each face of the dice, a distinct nu

HDU 4652 Dice (概率DP)

Dice Problem Description You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form: 0

CodeForcesGym 100502D Dice Game

Dice Game Time Limit: 1000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGym. Original ID: 100502D64-bit integer IO format: %I64d      Java class name: (Any) Gunnar and Emma play a lot of board games at home, so they own many dice

Spring-1-F Dice(HDU 5012)解题报告及测试数据

Dice Time Limit:1000MS     Memory Limit:65536KB Description There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a 1.a 2,a 3,a 4,a 5,a 6 to be numbers written on top face, bottom face, left face, r

hdu 5012 Dice

Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 440    Accepted Submission(s): 259 Problem Description There are 2 special dices on the table. On each face of the dice, a distinct number w

HDU - 5012 Dice(BFS)

Problem Description There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a1.a2,a3,a4,a5,a6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A.

Hdu 4386 Play the Dice 解题报告

hdu 4586---Play the dice 解题思路:概率 题目描述:一个骰子有n面,每面朝上的概率相同,并且每一面上面都有一个数字,其中有m面是彩色的,代表掷到彩色面的时还可以继续掷下去,问最终掷得的数字的期望是多少? 解题方法: 方法一:只考虑单独掷每一次的情况,可以发现,每次掷到的期望是和先前无关的,假设a=sum/n(每掷一次的期望都是a),比如:掷第一次的时候期望是a,掷第二次的时候期望便是(m/n)*a,因为有(m/n)的概率能够掷第二次..依次可以继续下去,等比求和即可. u

1248 - Dice (III)

  PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair, that m