HDOJ 4652 Dice
2014-11-04 11:25
218 查看
[align=center] [/align] 期望DP +数学推导 DiceTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 337 Accepted Submission(s): 223 Special Judge [align=left]Problem Description[/align] 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. [align=left]Input[/align] 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. [align=left]Output[/align] For each query, output the corresponding result. The answer will be considered correct if the absolute or relative error doesn't exceed 10-6. [align=left]Sample Input[/align] 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 [align=left]Sample Output[/align] 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 [align=left]Source[/align] 2013 Multi-University Training Contest 5 题意:一个m个面的筛子。两种询问:(1)平均抛多少次后使得最后n次的面完全一样;(2)平均抛多少次后使得最后n次的面完全不同? 思路:设dp[i]表示i次完全相同、不同时还需要抛的次数期望。 (1)下面首先讨论完全相同的情况。 (2)完全不同的情况: |
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 6 using namespace std; 7 8 int main() 9 { 10 int t,m,n,s; 11 while(scanf("%d",&t)!=EOF) 12 { 13 while(t--) 14 { 15 scanf("%d%d%d",&s,&m,&n); 16 if(s==0) 17 { 18 printf("%.9lf\n",(1.-pow(m,n))/(1-m)); 19 } 20 else if(s==1) 21 { 22 double sum=1.,tmp=1.; 23 for(int i=1;i<n;i++) 24 { 25 tmp=tmp*m/(m-i); 26 sum+=tmp; 27 } 28 printf("%.9lf\n",sum); 29 } 30 } 31 } 32 return 0; 33 }
相关文章推荐
- 【HDOJ】4652 Dice
- HDU 4652 Dice
- HDU 4652 Dice (概率DP)
- HDOJ-5012-Dice 解题报告
- HDU 4652 Dice(概率dp)
- HDU 4652 Dice (概率DP)
- hdu 4652 Dice(期望)
- 【HDOJ5955】Guessing the Dice Roll(概率DP,AC自动机,高斯消元)
- hdu 4652 Dice(dp)
- HDOJ 5012 Dice
- hdu 4652 Dice
- hdoj 4586 Play the Dice
- HDU 4652 Dice (概率DP)
- HDU 4652 Dice
- HDU 4652 Dice(概率dp)
- hdu 4652 Dice 概率DP
- 【搜索】 HDOJ 5012 Dice
- HDU 4652 Dice (概率DP)
- HDU 4652 Dice (概率DP)
- HDU 4652 Dice(期望)