您的位置:首页 > 其它

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).

///////////////////////////////////////////////////////////////////////////
//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
*/
///////////////////////////////////////////////////////////////////////////
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: