/*
题意:一个迷宫有n扇门,每次你可以任意选一扇门,每一扇门都有一个值xi
如果xi > 0 ,表示可以走出迷宫,走出迷宫需要的时间为xi; 否则 回到原来的位置,用了xi的时间;
问你走出迷宫所需时间的期望值
题解:设有k个门可以走出迷宫,一次走出迷宫的概率为k/n,期望次数为n/k;
走一次迷宫的平均时间为 sum/n;
则走出迷宫的时间期望为 sum/n * n/k;
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int gcd(int a,int b)
{
if(b==0) return a;
gcd(b,a%b);
}
int main()
{
int t,n,x,Case = 1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int sum = 0,k = 0;
for(int i = 0;i < n;i++)
{
scanf("%d",&x);
if(x > 0) k ++;
sum += abs(x);
}
printf("Case %d: ",Case++);
if(k == 0) puts("inf");
else
{
int r = gcd(sum,k);
printf("%d/%d\n",sum/r,k/r);
}
}
}
LIGHTOJ 1027(概率 - 期望)
最新推荐文章于 2021-05-10 22:54:21 发布