#P3772. [CTSC2017] 游戏
[CTSC2017] 游戏
Description
Xiao R and his roommate Xiao B are playing a game in their dorm. They play a total of games, and each game ends with either Xiao R winning or Xiao B winning.
In game 1, the probability that Xiao R wins is , and the probability that Xiao B wins is . Except for the first game, in each game the probability that Xiao R wins depends on whether Xiao R won the previous game.
Specifically:
-
If in game () Xiao R won, then in game the probability that Xiao R wins is , and the probability that Xiao B wins is .
-
If in game () Xiao B won, then in game the probability that Xiao R wins is , and the probability that Xiao B wins is .
Xiao D often comes to watch Xiao R and Xiao B play, so he knows the outcomes of some games. He wants to know, under the information he currently knows, what the expected total number of games won by Xiao R is among the games.
Xiao D does not have a good memory: sometimes he recalls the outcome of some game and adds it to his known information; sometimes he forgets a previously remembered outcome and removes it from his known information. Your task is: whenever Xiao D adds or deletes one piece of information, compute, based on Xiao D’s current known information, the expected total number of games won by Xiao R among the games.
Note: If Xiao D forgets the result of a game and later recalls it again, the two remembered outcomes are not necessarily the same. You do not need to care whether his memory matches the actual situation; you only need to compute the answers according to his memory.
Input Format
The first line contains two positive integers and a string . They indicate that Xiao R and Xiao B play games in total, Xiao D performs operations of modifying his known information, and the data is of type . The string is provided to help obtain partial scores; you may not need this input. See [Constraints] for its meaning.
The next lines: the 1st line contains a real number , meaning that in the first game the probability that Xiao R wins is . Line () contains two real numbers . Here, means that if Xiao R won game , then in game the probability that Xiao R wins is ; means that if Xiao B won game , then in game the probability that Xiao R wins is .
The next lines each describe one change to Xiao D’s known information. There are two types of operations.
-
add i cmeans Xiao D recalls the outcome of game and adds it to his known information. If it means Xiao B won game ; if it means Xiao R won game . It is guaranteed that are integers with . If this is not the first operation, it is guaranteed that after the previous operation the known information does not contain the result of game . -
del imeans Xiao D forgets the outcome of game and removes it from his known information. It is guaranteed that is an integer with , and that after the previous operation the known information contains the result of game .
Output Format
For each operation, output one real number on a single line: after the operation, under the current known information, the expected total number of games won by Xiao R among the games.
3 3 A
0.3
0.5 0.2
0.9 0.8
add 1 1
add 3 0
del 1
2.350000
1.333333
0.432749
Hint
[Scoring]
Your answer is judged correct if its absolute error from the correct answer is within .
You receive full score only if all your answers are correct; otherwise you receive points.
Please note the output format: output exactly one answer per line, and each answer must be a single real number. The length of each line must not exceed . Wrong output formats will be judged as points.
[Constraints]
For of the data, , , .
For of the data, input values have at most four decimal places.
There are test data points in total, each worth points. The specific assumptions for each test point are shown in the table below:

[Xiao R teaches you math]
You may use the following formulas.
- Conditional probability
We write to denote the probability that event occurs given that event occurs. Conditional probability can be computed by: where denotes the probability that both event and event occur, and denotes the probability that event occurs.
- Bayes’ formula (Bayes)
From conditional probability, we can derive Bayes’ formula:
- Law of total probability
If a random variable has possible values, namely , then

[Warm reminder]
In this problem, if you want to get full score, you may need to consider errors introduced by floating-point arithmetic. Using only addition and multiplication will not introduce large errors, but please be cautious with subtraction and division.
-
Subtracting two numbers that are close in value can introduce very large relative error.
-
If the determinant of a matrix is very small, computing the inverse of that matrix can introduce considerable error.
Of course, even if your algorithm is mathematically correct but does not consider floating-point errors, you may still obtain partial scores.
Translated by ChatGPT 5
京公网安备 11011102002149号