题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1027
题意:
你面前有n个门,每个对应一个数字,若为正xi,代表xi分钟后你会从它走出迷宫,负数则说明你会在-xi分钟后回到出发点且失去记忆。求出去的时间的期望。
代码:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 10000;
int t ,n;
int p[MAXN];
long long gcd (long long a,long long b)
{
if (b == 0) return a;
else return gcd (b,a%b);
}
int main()
{
cin>>t;
for(int cases=1;cases<=t;cases++)
{
cin>>n;
int num = 0;
long long sum =0;
for(int i=1;i<=n;i++)
{
cin>>p[i];
if (p[i] > 0) num++;
sum += abs(p[i]);
}
int tmp = gcd(sum,num);
num = num/tmp;
sum = sum/tmp;
cout<<"Case "<<cases<<": ";
if (num!=0) cout<< sum <<"/"<< num <<endl;
else cout<<"inf"<<endl;
}
return 0;
}