zoukankan      html  css  js  c++  java
  • luogu P1297 [国家集训队]单选错位 |数学期望

    题目描述

    gx 和 lc 去参加 noip 初赛,其中有一种题型叫单项选择题,顾名思义,只有一个选项是正确答案。

    试卷上共有 (n) 道单选题,第 (i) 道单选题有 (a_i)​ 个选项,这 (a_i)​ 个选项编号是 (1,2,3,ldots,a_i)​,每个选项成为正确答案的概率都是相等的。

    lc 采取的策略是每道题目随机写上 (1 sim a_i)​ 的某个数作为答案选项,他用不了多少时间就能期望做对 (sum_{i=1}^n frac{1}{a_i}) 道题目。gx 则是认认真真地做完了这 (n) 道题目,可是等他做完的时候时间也所剩无几了,于是他匆忙地把答案抄到答题纸上,没想到抄错位了:第 (i) 道题目的答案抄到了答题纸上的第 (i+1) 道题目的位置上,特别地,第 (n) 道题目的答案抄到了第 (1) 道题目的位置上。

    现在 gx 已经走出考场没法改了,不过他还是想知道自己期望能做对几道题目,这样他就知道会不会被 lc 鄙视了。

    我们假设 gx 没有做错任何题目,只是答案抄错位置了。

    输入格式

    (n) 很大,为了避免读入耗时太多,输入文件只有 555 个整数参数 (n, A, B, C, a_1)​,由上交的程序产生数列 (a)。下面给出 pascal/C/C++ 的读入语句和产生序列的语句(默认从标准输入读入):

    // for pascal
    readln(n,A,B,C,q[1]);
    for i:=2 to n do
    q[i] := (int64(q[i-1]) * A + B) mod 100000001;
    for i:=1 to n do
    q[i] := q[i] mod C + 1;

    // for C/C++
    scanf("%d%d%d%d%d", &n, &A, &B, &C, 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] % C + 1;

    选手可以通过以上的程序语句得到 (n) 和数列 (a)(a) 的元素类型是 (32) 位整数),(n)(a) 的含义见题目描述。

    输出格式

    输出一个实数,表示 gx 期望做对的题目个数,保留三位小数。


    设两道相邻题目长度为x,y,仔细研究发现两道题答案相同的概率是1/max(x,y)

    乘以个1,就是数学期望了,相加就好了

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int N=1e7+10;
    #define ll long long
    #define db double
    inline int read(){
    	int x=0; char c=getchar();
    	while(c<'0'||c>'9')c=getchar();
    	while('0'<=c&&c<='9'){ x=(x<<1)+(x<<3)+(c^48); c=getchar(); }
    	return x;
    }
    int a[N],n;
    inline void in(){
    	int A,B,C;
    	scanf("%d%d%d%d%d", &n, &A, &B, &C, a + 1);
    	for (int i = 2; i <= n; i++)
    	a[i] = ((ll) a[i - 1] * A + B) % 100000001;
    	for (int i = 1; i <= n; i++)a[i] = a[i] % C + 1;
    }
    int main(){
    	in();
    	db ans=0;
    	for(int i=1;i<n;i++)ans+=(db)1/max(a[i],a[i+1]);
    	ans+=(db)1/max(a[1],a[n]);
    	printf("%.3f
    ",ans);
    }
    
    
  • 相关阅读:
    Tomcat
    二叉树
    CDOJ 1962 天才钱vs学霸周2【最大流】
    次小生成树(POJ1679/CDOJ1959)
    CDOJ1927 爱吃瓜的伊卡洛斯(2) 【并查集】启发式合并+set
    HDU 1074 Doing Homework(DP状态压缩)
    uva 11367 (Dijkstra+DP)
    线段树模板
    openpose pytorch代码分析
    opencv图片坐标和数组下标
  • 原文地址:https://www.cnblogs.com/naruto-mzx/p/12677581.html
Copyright © 2011-2022 走看看