zoukankan      html  css  js  c++  java
  • LightOJ 1248 Dice (III) (水题,期望DP)

    题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少。

    析:这个题很水啊,就是他解释样例解释的太。。。我鄙视他,,,,,

    dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新的一面,另一种是看到旧的一面,然后就很出答案了。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e16;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e5 + 10;
    const int mod = 1e9 + 7;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c){
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    double dp[maxn];
    
    int main(){
      int T;  cin >> T;
      for(int kase = 1; kase <= T; ++kase){
        scanf("%d", &n);
        dp[1] = 1.0;
        for(int i = 2; i <= n; ++i)
          dp[i] = (dp[i-1] * (n - i + 1) + i - 1) / (n - i + 1) + 1.0;
        printf("Case %d: %.10f
    ", kase, dp[n]);
      }
      return 0;
    }
    

      

  • 相关阅读:
    JAVA中变量的类型及命名规范
    JAVA、JDK等入门概念,下载安装JAVA并配置环境变量
    大家好,我是一个JAVA初学者,想在这里记下自己学习过程中的点点滴滴,请多多关照
    多线程并发问题解决之redis锁
    设计模式之动态代理
    设计模式之静态代理
    spring之IOC模拟实现
    spring boot+kafka整合
    metrics+spring+influxdb整合
    MongoError: no primary found in replicaset
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7326354.html
Copyright © 2011-2022 走看看