LightOJ-1027-A Dangerous Maze (probability)

link:

https://vjudge.net/problem/LightOJ-1027#author=634579757

Meaning of the questions:

You are in a maze; seeing n doors in front of you in beginning. You can choose any door you like. The probability for choosing a door is equal for all doors.

If you choose the ith door, it can either take you back to the same position where you begun in xi minutes, or can take you out of the maze after xi minutes. If you come back to the same position, you can't remember anything. So, every time you come to the beginning position, you have no past experience.

Now you want to find the expected time to get out of the maze.

Ideas:

Consider when x is greater than 0 out time is desired. 1 / n- T, 0 is less than the desired time out. 1 / n- (T + d). Wherein d is the desired overall time out.
Release. 1 = D / n- SUMT NE + / n- D. SUMT wherein the total time, and abs (t) and. ne of them is negative.

Code:

#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
#include <set>
#include <iterator>
#include <cstring>
#include <assert.h>
using namespace std;

typedef long long LL;

int n;

int main()
{
    int t, cnt = 0;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%d", &n);
        int sum = 0, ne = 0, v;
        bool flag = false;
        for (int i = 1;i <= n;i++)
        {
            scanf("%d", &v);
            if (v > 0)
                flag = true;
            if (v < 0)
                ne++;
            sum += abs(v);
        }
        if (!flag)
            printf("Case %d: inf\n", ++cnt);
        else
            printf("Case %d: %d/%d\n", ++cnt, sum/__gcd(sum, n-ne), (n-ne)/__gcd(sum, n-ne));
    }

    return 0;
}

Guess you like

Origin www.cnblogs.com/YDDDD/p/11447609.html