期望。
不管人家说这题水不水吧,我感觉这道题挺好的,还复习了下数学期望。
分析写着太麻烦,我从这抄的 http://www.cnblogs.com/kuangbin/archive/2013/05/16/3082750.html
设所求期望为ans
那么
ans=1/N *(A[B[1]]+ans) + 1/N *(A[B[2]]+ans) + ...1/N *(A[B[M]]+ans) + 1/N A[k]+....
ans=M/N *ans+1/N*(A[1]+A[2]+A[3]+....+A[N]);
(N-M)ans= A[1]+A[2]+...+A[N]=sum;
如果sum==0,答案为0.00
如果sum!=0,N-M==0 答案为inf
否则答案就是sum/(N-M);
#include <iostream>
#include <stdio.h>
using namespace std;
int n, m;
int main()
{
int temp, sum;
while(scanf("%d", &n) != EOF)
{
sum = 0;
for(int i = 0; i < n; i++)
{
scanf("%d", &temp);
sum += temp;
}
scanf("%d", &m);
for(int i = 0; i < m; i++)
scanf("%d", &temp);
if(sum == 0)
printf("0.00\n");
else if(m == n)
printf("inf\n");
else
{
double res = (n - m) * 1.0;
res = sum / res;
printf("%.2lf\n", res);
}
}
return 0;
}