版权声明:原创,未经作者允许禁止转载 https://blog.csdn.net/Mr_wuyongcong/article/details/87979936
正题
题目大意
道题,第 道 个选项,选择每个选项的概率第相等的。但是每个选择都会填到后一道题。求对的期望题数。
解题思路
考虑若前面一道题有
个选项,后一道有
个选项,那么其实就是求一个在
随机选择,一个在
随机选择,求相等概率。然后总共会有
种可能,然后又
种正确情况。那么这个正确概率就是
#include<cstdio>
#include<algorithm>
using namespace std;
int n,A,B,C,a[10000010];
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;
a[n+1]=a[1];
for(int i=1;i<=n;i++)
ans+=(double)min(a[i],a[i+1])/a[i]/a[i+1];
printf("%.3lf",ans);
}