#P1297. [国家集训队] 单选错位
[国家集训队] 单选错位
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 single-choice questions on the paper. The -th question has options, numbered . Each option is equally likely to be the correct answer.
lc’s strategy is to randomly write down some number from as the answer for each question. In little time, he can expect to get questions correct. gx carefully solved all 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 -th question was written in the position of the -th question on the answer sheet. Specifically, the answer to the -th question was written in the position of the -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
is large. To avoid slow input, the input file contains only integers , and the submitted program generates the sequence . 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 and the sequence using the code above (the elements of are -bit integers). The meanings of and 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 |
|---|---|---|---|
.
There are cases, each occurring with probability . The expected number of correct answers for gx is . (In comparison, lc’s random strategy yields an expectation of .)
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号