#P16520. [GKS 2015 #E] Not So Random

    ID: 16497 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>数学2015Special Judge期望Google Kick Start

[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 KK, and always performs one of the following three operations:

  • with probability A/100A/100: return the bitwise AND of the input and KK
  • with probability B/100B/100: return the bitwise OR of the input and KK
  • with probability C/100C/100: return the bitwise XOR of the input and KK

(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 NN 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 XX 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, TT. TT test cases follow; each consists of one line with six integers N,X,K,A,B,N, X, K, A, B, and CC. 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 100100 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 yy is the expected value of the final output. yy will be considered correct if it is within an absolute or relative error of 10910^{-9} 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 55 if AND or OR happens and 00 if XOR happens. So the probability of getting 55 is (0.1+0.50.1 + 0.5) and the probability of getting 00 is 0.40.4. So the expected final output is 5×0.6+0×0.4=35 \times 0.6 + 0 \times 0.4 = 3.

In sample test case #2, the final output will be 55 with probability 0.720.72, and 00 otherwise.

Limits

1T501 \le T \le 50.
0A1000 \le A \le 100.
0B1000 \le B \le 100.
0C1000 \le C \le 100.
A+B+C=100A + B + C = 100.

Small dataset (Test Set 1 - Visible)

1N101 \le N \le 10.
0X1040 \le X \le 10^4.
0K1040 \le K \le 10^4.

Large dataset (Test Set 2 - Hidden)

1N1051 \le N \le 10^5.
0X1090 \le X \le 10^9.
0K1090 \le K \le 10^9.