zoukankan      html  css  js  c++  java
  • P1297 单选错位

    这是一道我们的考试题

    题意:

    洛谷

    gx把第\(i\) 题的答案涂到了 \(i+1\) 上 让我们求出gx 答对的期望

    前置芝士

    期望
    定义:试验中每次可能结果的概率乘以其结果的总和(来自百度某科 滑稽
    性质:\(E(ax+by)\) = \(xE(a)\) * \(yE(b)\)
    计算式: \(E(x)\) = \(\sum_{i=1}^{\infty}\) \(w_i * p_i\)

    solution

    每个题的选项不同,考虑分情况讨论。

    1. 当两个题的选项数相同时,gx答对的概率为\({1} \over {a_i}\)
    2. 当前一道题的选项数大于后一道题时,gx答对的概率为 \({a_i+1} \over {a_i * a_i+1}\) = \({1} \over {a_i}\)
    3. 当后一道题的选项数大于前一道题时,gx答对的概率为 \({a_i} \over {a_i * a_i+1}\) = \({1} \over {a_i+1}\)

    综上这道题的总柿子为 \({min(a_i , a_i+1)} \over {a_i * a_i+1}\) = \({1} \over {max(a_i,a_i+1)}\)

    代码

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int n,A,B,p;
    int a[20000010];
    double ans;
    int main()
    {
       scanf("%d%d%d%d%d", &n, &A, &B, &p, a + 1);
       for (int i = 2; i <= n; i++)	a[i] = ((long long) a[i - 1] * A + B) % 100000001;
       for (int i = 1; i <= n; i++) a[i] = a[i] % p + 1;
       a[n+1] = a[1];
       for(int i = 1; i <= n; i++) ans += 1 / (double) max(a[i],a[i+1]);
       printf("%.3lf",ans);
       return 0;
    }
    
  • 相关阅读:
    springmvc 处理静态资源
    springmvc jsp 获取 上下文
    springmvc 如何设置首页
    servlet-mapping url-pattern / 和 /*区别
    nginx支持php
    openresty 变量
    git tag用法
    python 导入模块,__init__.py 的作用
    python 转码问题
    python装饰器
  • 原文地址:https://www.cnblogs.com/genshy/p/13355531.html
Copyright © 2011-2022 走看看