• LightOJ 1027 A Dangerous Maze (数学期望)


    题意:你面前有 n 个门,每次你可以选择任意一个进去,如果xi是正数,你将在xi后出去,如果xi是负数,那么xi后你将回来并且丢失所有记忆,问你出去的期望。

    析:两种情况,第一种是直接出去,期望就是 1/n * xi

    第二种是回来了,再出去 1/n*(-xi+E),

    然后就可以得到 E = sum / (n - cnt)。

    sum是所有的数的绝对值的和,cnt是xi为负数的个数。

    代码如下:

    #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 = 1e6 + 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;
    }
    
    
    int main(){
      int T;  cin >> T;
      for(int kase = 1; kase <= T; ++kase){
        scanf("%d", &n);
        int cnt = n;
        int sum = 0;
        for(int i = 0; i < n; ++i){
          scanf("%d", &m);
          sum += abs(m);
          if(m < 0)  --cnt;
        }
        printf("Case %d: ", kase);
        if(cnt == 0){
          printf("inf
    ");
          continue;
        }
        int g = gcd(sum, cnt);
        printf("%d/%d
    ", sum/g, cnt/g);
      }
      return 0;
    }
    

      

  • 相关阅读:
    目录:数据挖掘
    目录:工具的安装与激活
    目录:Django框架开发Web系统的功能实现过程
    Python3.5在jupyter中使用graphviz画决策树(包括graphviz-2.38.msi的安装)
    2020年全国高校计算机能力挑战赛Python程序设计初赛
    离群异常值与重复数据检测
    数据描述性统计度量方法
    数据挖掘的方法
    Nginx+uWSGI+Django部署方案的详细实现过程
    VMware的联网配置及虚拟机IP配置
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7324954.html
Copyright © 2020-2023  润新知