# 单选错位

### 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

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

$ans=\sum(每道题做对的期望)$


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
int n, A, B, C, a1;
double ans = 0;
int a[maxn];

inline void putit()
{
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;
}

inline void workk()
{
for(int i = 1; i < n; ++i)	ans += (1.0) / max(a[i], a[i + 1]);
ans += (1.0) / max(a[n], a[1]);
}

int main()
{
putit();
workk();
printf("%.3f\n", ans);
return 0;
}



posted @ 2018-03-20 11:28  沛霖  阅读(102)  评论(0编辑  收藏  举报