zoukankan      html  css  js  c++  java
  • HDU4405 Aeroplane chess(期望dp)

    题意

    抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html

    正在玩飞行棋。输入n,m表示飞行棋有n个格子,有m个飞行点,然后输入m对u,v表示u点可以直接飞向v点,即u为飞行点。如果格子不是飞行点,扔骰子(1~6等概率)前进。否则直接飞到目标点。每个格子是唯一的飞行起点,但不是唯一的飞行终点。问到达或越过终点的扔骰子期望数。

    从0出发!!

    Sol

    比较zz的期望dp

    设$f[i]$表示从$i$出发,到达$n$的期望步数

    转移的时候讨论一下即可

    /*
    
    */
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<vector>
    #include<set>
    #include<queue>
    #include<cmath>
    #define Pair pair<int, int>
    #define MP(x, y) make_pair(x, y)
    #define fi first
    #define se second
    //#define int long long 
    //#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 22)], *p1 = buf, *p2 = buf;
    using namespace std;
    const int MAXN = 1e5 + 10, INF = 1e9 + 10;
    const double eps = 1e-10;
    inline int read() {
        char c = getchar(); int x = 0, f = 1;
        while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
    int N, M, to[MAXN];
    double f[MAXN];
    int main() {
        while(scanf("%d %d", &N, &M)) {
            if((N == 0) && (M == 0)) break;
            memset(to, 0, sizeof(to));
            memset(f, 0, sizeof(f));
            for(int i = 1; i <= M; i++) {
                int x = read(), y = read();
                to[x] = y;
            }
            for(int x = N - 1; x >= 0; x--) {
                if(to[x]) f[x] = f[to[x]];
                else {
                    for(int j = 1; j <= 6; j++) f[x] += f[x + j];
                    f[x] /= 6; f[x]++;
                }
            }
            printf("%.4lf
    ", f[0]);
        }
        return 0;
    }
    /*
    
    */
  • 相关阅读:
    AtCoder Beginner Contest 089 D
    AtCoder Beginner Contest 088 D Grid Repainting
    [odb-users] query results not being cached?
    cmake使用示例与整理总结
    CMake使用总结
    Create schema error (unknown database schema '')
    [odb-users] Create schema error (unknown database schema '')
    ODB(C++ ORM)用Mingw的完整编译过程
    odb_sqlite_demo
    ODB——基于c++的ORM映射框架尝试(使用)
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9527783.html
Copyright © 2011-2022 走看看