# 【JZOJ5616】沧海尘记

Description

Input

Output

Sample

Input:
2 2 3 5
Output:
0.545454545454545454 0.454545454545454545


Data Constraint

# Analysis

${\mathrm{\forall }}_{x\in A}trans\left(x\right)\in A$$\forall_{x\in A} trans(x)\in A$
${\mathrm{\forall }}_{trans\left(x\right)=y,y\ne x}trans\left(trans\left(\cdots trans\left(y\right)\right)\right)\ne x$$\forall_{trans(x)=y,y\not=x} trans(trans(\cdots trans(y)))\not=x$
${\mathrm{\exists }}_{x\in A}trans\left(x\right)=x$$\exists_{x\in A} trans(x)=x$

# code

#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define N 2510
#define ld long double

using namespace std;

ld A[2][N],p[N][N];
int n,a,b,c,q[N][N],s[N],t;

int main(){
scanf("%d %d %d %d",&n,&a,&b,&c);
for(int l=0,i=1;i<=n;i++){
for(int j=1;j<=n;j++){
l=q[i][j]=(l*a+b)%c;s[i]+=q[i][j]+1;
}
for(int j=1;j<=n;j++)p[i][j]=(ld)(q[i][j]+1)/(ld)s[i];
}
int can=1,las=0,now=1;A[0][1]=1.0;
for(;can;las^=1,now^=1){
can=0;for(int i=1;i<=n;i++)A[now][i]=0.0;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)A[now][i]+=A[las][j]*p[j][i];
for(int i=1;i<=n;i++)if(fabs(A[now][i]-A[las][i])>=4e-16){can=1;break;}
}
for(int i=1;i<=n;i++)printf("%.18Lf ",A[now][i]);
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120