#P16520. [GKS 2015 #E] Not So Random
[GKS 2015 #E] Not So Random
题目描述
There is a certain "random number generator" (RNG) which takes one nonnegative integer as input and generates another nonnegative integer as output. But you know that the RNG is really not very random at all! It uses a fixed number , and always performs one of the following three operations:
- with probability : return the bitwise AND of the input and
- with probability : return the bitwise OR of the input and
- with probability : return the bitwise XOR of the input and
(You may assume that the RNG is truly random in the way that it chooses the operation each time, based on the values of A, B, and C.)
You have copies of this RNG, and you have arranged them in series such that output from one machine will be the input for the next machine in the series. If you provide as an input to the first machine, what will be the expected value of the output of the final machine in the series?
输入格式
The first line of the input gives the number of test cases, . test cases follow; each consists of one line with six integers and . Respectively, these denote the number of machines, the initial input, the fixed number with which all the bitwise operations will be performed (on every machine), and times the probabilities of the bitwise AND, OR, and XOR operations.
输出格式
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and is the expected value of the final output. will be considered correct if it is within an absolute or relative error of of the correct answer.
3
1 5 5 10 50 40
2 5 5 10 50 40
10 15 21 70 20 10
Case #1: 3.0000000000
Case #2: 3.6000000000
Case #3: 15.6850579098
提示
In sample test case #1, the final output will be if AND or OR happens and if XOR happens. So the probability of getting is () and the probability of getting is . So the expected final output is .
In sample test case #2, the final output will be with probability , and otherwise.
Limits
.
.
.
.
.
Small dataset (Test Set 1 - Visible)
.
.
.
Large dataset (Test Set 2 - Hidden)
.
.
.