#P5472. Card Shuffling and Expected Score
Card Shuffling and Expected Score
Card Shuffling and Expected Score
Little S and Little F are playing a game called "Dou Di Zhu". Little S is not as strong at playing and wants to tamper with the shuffling process to improve his odds. A deck of cards contains (n) cards labeled from (1) to (n) (from top to bottom). The score of card (i) is given by (f(i)), and in this problem, (f(i)) can only take two possible forms: (f(i)=i) or (f(i)=i^2).
The shuffling is performed over (m) rounds. In each round (i), the following steps occur:
- Little S takes the top (A_i) cards, splitting the deck into two piles: the first pile (top (A_i) cards) and the second pile (remaining (n-A_i) cards). The internal order of the cards in each pile is preserved. (Note that if (A_i=0) or (A_i=n), one of the piles is empty.)
- Then the two piles are merged into a new deck. Suppose at some point the first pile has (X) cards and the second has (Y) cards. With probability (\frac{X}{X+Y}) the bottom card of the first pile is chosen, and with probability (\frac{Y}{X+Y}) the bottom card of the second pile is chosen. The chosen card is placed on the top of the new deck.
- This process is repeated until both piles are empty, thus completing one round of shuffling.
Since the shuffling is random, Little S cannot tell which card ends up at a specific position. He wants to know, after (m) rounds of shuffling, what is the expected score of the card at a given position. There will be (Q) queries, each asking for the expected score at a specific position.
inputFormat
The first line contains three integers \(n, m, Q\).
The second line contains \(n\) integers; the \(i\)th integer is either 1 or 2. If the \(i\)th integer is 1 then \(f(i)=i\); if it is 2 then \(f(i)=i^2\>.
The following \(m\) lines each contain an integer \(A_i\) (\(0 \le A_i \le n\)).
The next \(Q\) lines each contain a query: a single integer \(p\) (the 1-indexed position in the deck after all rounds).
outputFormat
For each query, output the expected score of the card at that position. Print each answer on a new line. Answers within an absolute or relative error of 10^{-6} will be accepted.
sample
3 1 3
1 1 1
2
1
2
3
1.666667
2.000000
2.333333
</p>