洛谷 1297 [国家集训队]单选错位——期望

题目:https://www.luogu.org/problemnew/show/P1297

大水题。

考虑每一道题做对的概率。就是它的答案和上一道题的答案相同的概率。

设上一道题有a个选项,这道题有b个选项,则对于每个选项,对上的概率是1/a*1/b。

这样对上的情况有min( a,b )种。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e7+5;
int a[N],n,A,B,C;
double ans;
int main()
{
    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;
    for(int i=2;i<=n;i++)
    {
        int k=max(a[i-1],a[i]);
        ans+=1/(double)k;
    }
    int k=max(a[n],a[1]);ans+=1/(double)k;
    printf("%.3lf",ans);
    return 0;
}
原文地址:https://www.cnblogs.com/Narh/p/9203853.html