你在起点面对n扇门,每次等概率的选择一扇门,若这扇门是数字,花费Xi直接到达终点否则花费Xi回到起点。
这题很有思考价值。
设期望时间为E。 有E = 1/n * (Xi ) + 1/n * (E + Xi)
最后求解E即可。
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } int cnt1, cnt2; int main() { int T; scanf("%d", &T); int kase = 1; while (T--) { printf("Case %d:",kase++); cnt1 = cnt2 = 0; int n; ll tmp, sum; sum = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &tmp); if (tmp > 0) cnt1++; else cnt2++; sum += abs(tmp); } if (n == cnt2 ) { puts(" inf"); continue; } ll r1 = sum; ll r2 = n - cnt2; ll a = sum / (gcd(r1, r2)); ll b = r2 / (gcd(r1, r2)); printf(" %lld/%lld\n", a, b); } }