hdoj 4586 Play the Dice
2013-08-26 09:47
246 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4586
解题思路:设期望值为 E, sum=a[1]+a[2]+···+a
, 由于有 m 个是再来一次机会,故有 E=sum/n+(m/n)*E.
化简得:(n-m)*E=sum. 若 sum=0,则 E=0; 若 n=m, 则 E 为inf; 否则 E=sum/(n-m).
解题思路:设期望值为 E, sum=a[1]+a[2]+···+a
, 由于有 m 个是再来一次机会,故有 E=sum/n+(m/n)*E.
化简得:(n-m)*E=sum. 若 sum=0,则 E=0; 若 n=m, 则 E 为inf; 否则 E=sum/(n-m).
/////////////////////////////////////////////////////////////////////////// //problem_id: hdoj 4586 //user_id: SCNU20102200088 /////////////////////////////////////////////////////////////////////////// #include <algorithm> #include <iostream> #include <iterator> #include <iomanip> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cmath> #include <queue> #include <stack> #include <list> #include <set> #include <map> using namespace std; /////////////////////////////////////////////////////////////////////////// typedef long long LL; const double PI=acos(-1.0); const int x4[]={-1,0,1,0}; const int y4[]={0,1,0,-1}; const int x8[]={-1,-1,0,1,1,1,0,-1}; const int y8[]={0,1,1,1,0,-1,-1,-1}; typedef int T; T max(T a,T b){ return a>b? a:b; } T min(T a,T b){ return a<b? a:b; } /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //Add Code: /////////////////////////////////////////////////////////////////////////// int main(){ /////////////////////////////////////////////////////////////////////// //Add Code: int n,m,i,x; while(scanf("%d",&n)!=EOF){ int sum=0; for(i=0;i<n;i++){ scanf("%d",&x); sum+=x; } scanf("%d",&m); for(i=0;i<m;i++) scanf("%d",&x); if(sum==0) printf("0.00\n"); else if(n==m) printf("inf\n"); else printf("%.2lf\n",(sum+0.0)/(n-m)); } /////////////////////////////////////////////////////////////////////// return 0; } /////////////////////////////////////////////////////////////////////////// /* Testcase: Input: 6 1 2 3 4 5 6 0 4 0 0 0 0 1 3 Output: 3.50 0.00 */ ///////////////////////////////////////////////////////////////////////////
相关文章推荐
- HDOJ 4586 Play the Dice【数学】
- hdu 4586 Play the Dice
- HDU 4586:Play the Dice (数学)
- hdu 4586 Play the Dice (概率+等比数列)
- [hdu 4586] Play the Dice
- Play the Dice - HDU 4586 dp
- 概率dp求期望-hdu-4586-Play the Dice
- hdu 4586 Play the Dice(概率dp)
- poj 4586 Play the Dice(数论)
- hdu 4586 Play the Dice (概率+等比数列)
- (hdu 4586) Play the Dice
- 概率DP HDU 4586 play the dice
- HDU 4586 Play the Dice(规律+推导)
- hdu 4586 Play the Dice(概率期望题)
- HDU-4586 Play the Dice(概率期望)
- HDU 4586 Play the Dice 概率dp+等比数列 级数
- hdu 4586 Play the Dice 数学 概率
- HDU 4586 Play the dice(概率题,推公式)
- hdu 4586 Play the Dice
- hdu 4586 Play the Dice(数论)