2134: 单选错位 概率与期望

很简单的一道题啦。
ans=sigma(1/max(a[i],a[i+1]))

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long 
using namespace std;
int n,A,B,C,a[10000005];
double ans;
inline int read()
{
    int a=0,f=1; char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
    while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
    return a*f;
}
int main()
{
    n=read(); A=read(); B=read(); C=read(); a[1]=read();
    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; 
    a[n+1]=a[1];
    for (int i=1;i<=n;i++)
    {
        double x=(double)max(a[i],a[i+1]);
        ans+=1/x;
    }
    printf("%.3lf",ans);
    return 0;
}

你可能感兴趣的:(2134: 单选错位 概率与期望)