HDOJ 4652 Dice

时间:2023-01-18 16:14:57
 
期望DP +数学推导

Dice

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 337    Accepted Submission(s): 223
Special Judge

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 m n: ask for the expected number of tosses until the last n times results are all same.
1 m n: ask for the expected number of tosses until the last n consecutive results are pairwise different.
 
Input
The first line contains a number T.(1≤T≤100) The next T line each line contains a query as we mentioned above. (1≤m,n≤106) For second kind query, we guarantee n≤m. And in order to avoid potential precision issue, we guarantee the result for our query will not exceeding 109 in this problem.
 
Output
For each query, output the corresponding result. The answer will be considered correct if the absolute or relative error doesn't exceed 10-6.
 
Sample Input
6
0 6 1
0 6 3
0 6 5
1 6 2
1 6 4
1 6 6
10
1 4534 25
1 1232 24
1 3213 15
1 4343 24
1 4343 9
1 65467 123
1 43434 100
1 34344 9
1 10001 15
1 1000000 2000
 
Sample Output
1.000000000
43.000000000
1555.000000000
2.200000000
7.600000000
83.200000000
25.586315824
26.015990037
15.176341160
24.541045769
9.027721917
127.908330426
103.975455253
9.003495515
15.056204472
4731.706620396
 
Source

题意:一个m个面的筛子。两种询问:(1)平均抛多少次后使得最后n次的面完全一样;(2)平均抛多少次后使得最后n次的面完全不同?

思路:设dp[i]表示i次完全相同、不同时还需要抛的次数期望。

(1)下面首先讨论完全相同的情况。

HDOJ 4652 Dice

(2)完全不同的情况:

HDOJ 4652 Dice

 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; int main()
{
int t,m,n,s;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d%d%d",&s,&m,&n);
if(s==)
{
printf("%.9lf\n",(.-pow(m,n))/(-m));
}
else if(s==)
{
double sum=.,tmp=.;
for(int i=;i<n;i++)
{
tmp=tmp*m/(m-i);
sum+=tmp;
}
printf("%.9lf\n",sum);
}
}
}
return ;
}

HDOJ 4652 Dice的更多相关文章

  1. 【HDOJ】4652 Dice

    1. 题目描述对于m面的骰子.有两种查询,查询0表示求最后n次摇骰子点数相同的期望:查询1表示最后n次摇骰子点数均不相同的期望. 2. 基本思路由期望DP推导,求得最终表达式.(1) 查询0    不 ...

  2. HDU 4652 Dice(期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(2)平均抛多少 ...

  3. HDU 4652 Dice:期望dp(成环)【错位相减】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意: 给你一个有m个面的骰子. 两种询问: (1)"0 m n": “最后 ...

  4. HDU 4652 Dice (概率DP)

    版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/36685493 D ...

  5. hdu 4652 Dice 概率DP

    思路: dp[i]表示当前在已经投掷出i个不相同/相同这个状态时期望还需要投掷多少次 对于第一种情况有: dp[0] = 1+dp[1] dp[1] = 1+((m-1)*dp[1]+dp[2])/m ...

  6. HDU 4652 Dice

    嘟嘟嘟 题目大意就是对于一个m面的骰子,回答这么两个问题: 1.求连续扔n次都是同一数字的期望次数. 2.求连续扔n次每一次数字都不相同的期望次数. 对于期望dp特别菜的我来说,这道题已经算是很难了. ...

  7. 概率dp专场

    专题链接 第一题--poj3744 Scout YYF I  链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...

  8. Dice &lpar;HDU 4652&rpar;

    题面: m 面骰子,求1. 出现n个连续相同的停止 ;2. 出现n个连续不同的停止的期望次数.(n, m ≤ 10^6 ) 解析: 当然要先列式子啦. 用f[i](g[i])表示出现i个连续相同(不相 ...

  9. HDOJ 1009&period; Fat Mouse&&num;39&semi; Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. document&period;write 方法

    如果在文档加载结束后再调用document.write(),那么输出的内容将会 重写 整个页面. 某次被问及此问题,志之!

  2. HDOJ 1202 The calculation of GPA

    Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...

  3. Java swing(awt):事件监听机制的实现原理&plus;简单示例

    (1)实现原理 事件监听机制的实现: 参考图:事件模型_ActionEvent 为了节省资源,系统无法对某个事件进行实时的监听.故实现的机制是当发生某个事件后,处理代码将被自动运行,类似钩子一般.(回 ...

  4. C&num; DataSet数据导入Excel 修正版- &period;net FrameWork 4&period;0以上

    引入  Microsoft.Office.Interop.Excel.dll 格式:标题加了下划线,单元格内容居中 1 using System; using System.Data; using S ...

  5. Unity编译时找不到AndroidSDK的问题 &vert; Unable to list target platforms&lpar;转载&rpar;

    原文:http://www.jianshu.com/p/fe4c334ee9fe 现象 在用 Unity 编译 Android 平台的应用时,遇到 Unable to list target plat ...

  6. MySQL---insert into select from

    INSERT INTO perf_week(node_id,perf_time,pm25,pm10,temp,humi) SELECT node_id,'2016-12-22 11:55:00' AS ...

  7. 在线教育工具—白板系统的迭代1——bug监控排查

    近一年都在做一款在线教育工具(以下统称为“白板”)的开发工作,期间遇到N多的问题与坑,遂在此记录,并及时更新. 第一篇:关于资源访问填坑 因为是在线授课,所以使用我们白板的人员地域范围较广,基本上西到 ...

  8. mysql 给用户赋值权限

    解决办法 grant all privileges on *.* to joe@localhost identified by '1'; flush privileges; 拿 joe 1 登陆 附: ...

  9. LeetCode——Unique Binary Search Trees

    Question Given n, how many structurally unique BST's (binary search trees) that store values 1...n? ...

  10. js常用正则表达式,滚蛋吧!你们测试组bug,让你挑

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...