• lightoj1027(期望dp)


    有一个迷宫,有n个门,走每个的概率都是相同的

    每个门有一个数字,如果是正数ai,那么表示走ai天就能走出迷宫,如果是负数,那么走-ai天会回到原地,然后会忘记之前的事情,继续选择门去走

    所以,如果都是负数,那么是不可能走出迷宫的

    设d为走出迷宫的期望天数

    那么第三个样例就是 d = 1/3*3+1/3*(6+d)+1/3*(9+d)

    那么可以算出d=18/1

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <queue>
     7 #include <stack>
     8 #include <vector>
     9 #include <map>
    10 #include <set>
    11 #include <string>
    12 #include <math.h>
    13 using namespace std;
    14 #pragma warning(disable:4996)
    15 #pragma comment(linker, "/STACK:1024000000,1024000000")
    16 typedef __int64 LL;                   
    17 const int INF = 1<<30;
    18 /*
    19 
    20 */
    21 
    22 int gcd(int a, int b)
    23 {
    24     if (b == 0)return a;
    25     return gcd(b, a%b);
    26 }
    27 int main()
    28 {
    29     int t, n, x;
    30     scanf("%d", &t);
    31     int cnt1, cnt2;
    32     for (int k = 1; k <= t; ++k)
    33     {
    34         scanf("%d", &n);
    35         cnt1 = cnt2 = 0;;
    36         for (int i = 1; i <= n; ++i)
    37         {
    38             scanf("%d", &x);
    39             if (x < 0)
    40             {
    41                 cnt1 += -x;
    42                 cnt2++;
    43             }
    44             else
    45                 cnt1 += x;
    46         }
    47         if (cnt2 == n)
    48             printf("Case %d: inf
    ", k);
    49         else
    50         {
    51             int a = cnt1;
    52             int b = n - cnt2;
    53             int g = gcd(a, b);
    54             a /= g;
    55             b /= g;
    56             printf("Case %d: %d/%d
    ",k, a, b);
    57         }
    58     }
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    MUTC2013 E-Deque-hdu 4604
    MUTC7 C
    MUTC7 A-As long as Binbin loves Sangsang
    MUTC2013 J-I-number-hdu4608
    MUTC2013 H-Park Visit-hdu4607
    判断点是否在多边形内 扫描法
    蓝桥杯 基础练习 十六进制转八进制
    判断点是否在三角形内
    判断点在线段上
    向量的叉乘
  • 原文地址:https://www.cnblogs.com/justPassBy/p/4744277.html
Copyright © 2020-2023  润新知