题意:地上有n种棍子,其中有两种类型,一种类型是可识别,一种类型是不可识别,每个棍子都有一个权值。当你捡到可识别的,那么你以后就不会再捡这个棍子,如果是不可识别的,那么你有可能还会捡。每捡一根获得一个权值。问将所有棍子收集完的权值和的期望。
题解:期望
对于可识别的棍子,直接累加就可以。
对于不可识别的一根棍子,至少捡起一次期望次数=1+1/2+1/3+···+1/n(邮票收集问题),然后乘以权值就可以了。
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<map>
#include<sstream>
#include<iomanip>
#define ll long long
using namespace std;
const int maxn = 5e3 + 5;
int t, n, a, b;
double f[maxn];
int main() {
for (int i = 1; i < maxn; i++) {
f[i] = f[i - 1] + 1.0 / i;
}
scanf("%d", &t);
int cas = 0;
while (t--) {
scanf("%d", &n);
double ans = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a, &b);
if (b == 1) {
ans += a;
}
else {
ans += a * f[n];
}
}
printf("Case %d: %f\n", ++cas, ans);
}
return 0;
}