水概率DP,ANS=sigma(min(a[i],a[i-1])/(a[i]*a[i-1]))

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(int i=l;i<=r;i++)
 3 #define dec(i,l,r) for(int i=l;i>=r;i--)
 4 #define link(x) for(edge *j=h[x];j;j=j->next)
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define inf 1e9
 7 #define ll long long
 8 #define succ(x) (1<<x)
 9 #define lowbit(x) (x&(-x))
10 #define NM 10000000+5
11 using namespace std;
12 int read(){
13     int x=0,f=1;char ch=getchar();
14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
15     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
16     return x*f;
17 }
18 int n,A,B,C,a[NM];
19 double s;
20 int main(){
21     freopen("data.in","r",stdin);
22     scanf("%d%d%d%d%d",&n,&A,&B,&C,a+1);
23     for (int i=2;i<=n;i++) a[i] = ((long long)a[i-1] * A + B) % 100000001;
24     for (int i=1;i<=n;i++) a[i] = a[i] % C + 1;
25     a[n+1]=a[1];
26     inc(i,2,n+1)s+=(double)min(a[i],a[i-1])/a[i]/a[i-1];
27     printf("%.3lf\n",s);
28     return 0;
29 }
View Code

 

posted on 2016-03-20 12:15  onlyRP  阅读(180)  评论(0编辑  收藏  举报