P1297-[国家集训队]单选错位【期望概率】

版权声明:原创,未经作者允许禁止转载 https://blog.csdn.net/Mr_wuyongcong/article/details/87979936

正题


题目大意

n n 道题,第 i i a i a_i 个选项,选择每个选项的概率第相等的。但是每个选择都会填到后一道题。求对的期望题数。


解题思路

考虑若前面一道题有 x x 个选项,后一道有 y y 个选项,那么其实就是求一个在 1 x 1\sim x 随机选择,一个在 1 y 1\sim y 随机选择,求相等概率。然后总共会有 x y x*y 种可能,然后又 m i n ( x , y ) min(x,y) 种正确情况。那么这个正确概率就是
m i n ( x , y ) x y \frac{min(x,y)}{x*y}


c o d e code

#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);
}

猜你喜欢

转载自blog.csdn.net/Mr_wuyongcong/article/details/87979936