发现概率是∑1/两道题答案相同的概率,
稍加化简
#include <map> #include <ctime> #include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define F(i,j,k) for (int i=j;i<=k;++i) #define D(i,j,k) for (int i=j;i>=k;--i) int a[10000005],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; F(i,1,n-1) ans+=1.0/max(a[i],a[i+1]); ans+=1.0/max(a[n],a[1]); printf("%.3f\n",ans); }
时间: 2024-11-05 14:55:45