# BZOJ2134: 单选错位(期望乱搞)

Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 1101  Solved: 851
[Submit][Status][Discuss]

## Input

n很大，为了避免读入耗时太多，

// for pascal
for i:=2 to n do q[i] := (int64(q[i-1]) * A + B) mod 100000001;
for i:=1 to n do q[i] := q[i] mod C + 1;

// for C/C++
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;

n和a的含义见题目描述。
2≤n≤10000000, 0≤A,B,C,a1≤100000000

3 2 0 4 1

## Sample Output

1.167
【样例说明】
a[] = {2,3,1}

{1,1,1} {1,1,1} 3 1/6
{1,2,1} {1,1,2} 1 1/6
{1,3,1} {1,1,3} 1 1/6
{2,1,1} {1,2,1} 1 1/6
{2,2,1} {1,2,2} 1 1/6
{2,3,1} {1,2,3} 0 1/6

## Source

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=1e7+10;
char buf[1<<20],*p1=buf,*p2=buf;
{
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int N,A,B,C;
int a[MAXN];
int pre(int x)
{
return x==1?N:x-1;
}
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#endif
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;
double ans=0;
for(int i=1;i<=N;i++)
ans+=(double)min((double)1/a[i],(double)1/a[pre(i)]);

printf("%.3lf",ans);
return 0;
}

posted @ 2018-03-31 18:51  自为风月马前卒  阅读(176)  评论(0编辑  收藏  举报