Thursday, July 30, 2015

1027 - A Dangerous Maze

#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b)
{
    return (b == 0) ? a : gcd(b, a%b);
}
 
int main()
{
    long long T,n,i,sum,nValue,x,c=1;
    cin >> T;
    while(T--)
    {
        cin >> n;
        sum = 0;
        nValue = 0;
        for(i=0; i<n; i++)
        {
            cin >> x;
            sum += abs(x);
            if(x < 0)
                nValue++;
        }
        if(n == nValue)
        {
            cout << "Case " << c++ << ": inf" << endl;
            continue;
        }
        x = gcd(sum, n-nValue);
        if(n != nValue)
            cout << "Case " << c++ << ": " << sum/x << "/" << (n-nValue)/x << endl;
    }
    return 0;
}

No comments:

Post a Comment

Triathlon

Triathlon - CodeChef # include < bits/stdc++.h > using namespace std ; # define fi first # define se second # define mp ...