#P1297. [国家集训队] 单选错位

    ID: 295 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学WC/CTSC/集训队概率论,统计期望

[国家集训队] 单选错位

Description

gx and lc went to take the NOIP preliminary round. There is a type of problem called single-choice questions, meaning only one option is the correct answer.

There are nn single-choice questions on the paper. The ii-th question has aia_i options, numbered 1,2,3,,ai1, 2, 3, \ldots, a_i. Each option is equally likely to be the correct answer.

lc’s strategy is to randomly write down some number from 1ai1 \sim a_i as the answer for each question. In little time, he can expect to get i=1n1ai\sum_{i=1}^n \frac{1}{a_i} questions correct. gx carefully solved all nn questions, but when he finished, time was running out. He hurriedly copied his answers onto the answer sheet, but accidentally shifted them: the answer to the ii-th question was written in the position of the (i+1)(i+1)-th question on the answer sheet. Specifically, the answer to the nn-th question was written in the position of the 11-st question.

Now that gx has left the exam room, he cannot change his answers, but he still wants to know the expected number of questions he got correct, so he can tell whether he will be looked down upon by lc.

We assume gx did not solve any question incorrectly; only the positions of his answers were misaligned.

Input Format

nn is large. To avoid slow input, the input file contains only 55 integers n,A,B,C,a1n, A, B, C, a_1, and the submitted program generates the sequence aa. Below are the Pascal/C/C++ input statements and the sequence-generation statements (input is read from standard input by default):

// for pascal
readln(n,A,B,C,q[1]);
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;

Contestants can obtain nn and the sequence aa using the code above (the elements of aa are 3232-bit integers). The meanings of nn and aa are as described in the problem statement.

Output Format

Output a real number representing the expected number of questions gx gets correct, rounded to three decimal places.

3 2 0 4 1
1.167

Hint

[Sample Explanation]

Correct answers gx's answers Number correct Probability
{1,1,1}\{1,1,1\} 33 16\frac16
{1,2,1}\{1,2,1\} {1,1,2}\{1,1,2\} 11
{1,3,1}\{1,3,1\} {1,1,3}\{1,1,3\}
{2,1,1}\{2,1,1\} {1,2,1}\{1,2,1\}
{2,2,1}\{2,2,1\} {1,2,2}\{1,2,2\}
{2,3,1}\{2,3,1\} {1,2,3}\{1,2,3\} 00

a={2,3,1}a = \{2,3,1\}.

There are 66 cases, each occurring with probability 16\frac{1}{6}. The expected number of correct answers for gx is 3+1+1+1+1+06=76\frac{3+1+1+1+1+0}6 = \frac76. (In comparison, lc’s random strategy yields an expectation of 116\frac{11}6.)

For 30%30\% of the testdata, n10n \le 10, C10C \le 10.

For 80%80\% of the testdata, n104n \le 10^4, C10C \le 10.

For 90%90\% of the testdata, n5×105n \le 5 \times 10^5, C108C \le 10^8.

For 100%100\% of the testdata, 2n1072 \le n \le 10^7, 0A,B,C1080 \le A, B, C \le 10^8, 1ai1081 \le a_i \le 10^8.

Translated by ChatGPT 5