radio dislocation

radio dislocation

【Problem Description】

gx and lc went to participate in the noip preliminary round. There is a type of question called multiple choice questions. As the name suggests, only one option is the correct answer. There are n multiple-choice questions on the test paper , and the i -th multiple-choice question has a i options. The a i options are numbered 1, 2, 3,..., a i , and the probability of each option being the correct answer is equal. of. The strategy adopted by lc is to randomly write a number from 1- a i as an answer option for each question, and he can expect to do the right question in a short time. gx completed these n questions seriously , but when he finished, there was not much time left, so he hurriedly copied the answer on the answer sheet, but he did not expect to copy it in the wrong place: Question i The answer of the answer sheet is copied to the position of the i +1 question on the answer sheet , especially, the answer of the nth question is copied to the position of the first question . Now that gx is out of the exam room, he can't change it, but he still wants to know how many questions he expects to get right, so that he knows if he will be rejectedlc despised.

Let's assume gx didn't do anything wrong, just copied the answer in the wrong place.

【Input format】

n is very large. In order to avoid reading too much time, the input file has only 5 integer parameters n , A , B , C , a 1 , and the sequence a is generated by the submitted program. The following gives the pascal/C/C++ read-in statement and the statement that generates the sequence (the default is to read from the standard input):

 

 

Competitors can obtain n and sequence a ( the element type of a is a 32 - bit integer) through the above program statements . For the meaning of n and a , see the title description.

【Output format】

Output a real number, indicating the number of questions gx expects to get right, with three decimal places.

【Sample input】

3 2 0 4 1

【Example output】

1.167

【Example description】

a[] = {2,3,1}

correct answer

gx's answer

do the right thing

probability of occurrence

{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

There are a total of 6 situations, the probability of each situation is 1/6, gx expects to do (3+1+1+1+1+0)/6 = 7/6 questions. (In contrast, lc can expect to get 11/6 questions right at random)

【data range】

For 30% of the data n≤10, C≤10

For 80% of the data n≤10000, C≤10

For 90% of the data n≤500000, C≤100000000

For 100% of the data 2≤n≤10000000, 0≤ A,B,C, a 1 ≤100000000

 

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<cstring>
 6  
 7 using namespace std;
 8 
 9 template <typename tn> void read (tn & a) {
10     tn x = 0, f = 1;
11     char c = getchar();
12     while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar(); }
13     while (c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
14     a = f == 1 ? x : -x;
15 }
16 
17 const long long MAXN = 10000100;
18 long long n, A, B, C;
19 long long a[MAXN];
20 double ans;
21 
22 int main() {
23     read(n);
24     read(A);
25     read(B);
26     read(C);
27     read(a[1]);
28     ans = 0;
29     for (int i = 2; i <= n; ++i) {
30         a[i] = ((long long)a[i - 1] * A + B) % 100000001;
31     }
32     for (int i = 1; i <= n; ++i) {
33         a[i] = a[i] % C + 1;
34     }
35     a[0] = a[n];
36     for (int i = 1; i <= n; ++i) {
37         ans += (double)1 / (double)(max(a[i], a[i - 1]));
38     }
39     printf("%.3f\n", ans);
40     return 0;
41 } 
View Code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324517469&siteId=291194637