Link: click here
Test instructions
There is a very common game console in the arcade where many of the root tubes are lined up regularly. The ball falls from the top, and the pipe will wait for the probability to fall off the left or right side of the tube. But at the very edge of the ball will only fall on one side (, gray ball can only fall to the right gap). Now known to Co - n-1 Line Pipe, part i Line has Ai a pipe, if i is odd, then Ai equals m , if i is even,Ai equals m-1 . Ball from section 1 line k a pipe to the right of the drop down, asking the ball from the last line of each exit out of the probability.
-
Input
-
The first line is an integer t (1≤t≤50), which indicates that there is a T group of test data.
The first row of each group of data has two integers n (1≤n≤100) and M (2≤m≤10), which indicates that there are 2*n-1 rows of pipes, odd rows have m tubes, and even rows have m-1 tubes.
The second line is an integer k (1≤k≤m-1), which means that the ball falls from the right side of the 1th-line K-tube.
-
Output
-
Output m-1 Decimals, the number of I indicates the probability of the ball from the last line I exit.
Each decimal number retains six digits after the decimal point, separated by a space between the decimal and the decimal.
-
Sample input
-
13 32
-
Sample output
-
0.375000 0.625000
This problem is more interesting, in fact, a probabilistic simulation.
Ideas:
Defines a two-dimensional array, map[i][j] represents the probability that the first row of column J falls out of the pipe, because the ball is the top place, all we think of as long as the ball from each pipe fell down, the left and right of the probability of the problem is how many, the elements inside the array to carry out a special operation, here note , because the number of tubes on every other line is either one or more, or one more than the next line, so the points are discussed in odd and even:
Enter three number: N,m,k has just started to put: map[i][k]=1;
M is odd: there is map[i][1]=map[i-1][1] (the most side will only go away) +map[i-1][2]/2,map[i][m-1]=map[i-1][m1-1]/2+map[i-1][m];
M is even: map[i][1]= (map[i-1][1])/2,map[i][m]= (map[i-1][m-1])/2; Processing boundaries, you can control The imitation
For the middle number, we know that the probability of the ball falling is 1/2 on both sides of the previous line.
Therefore, the entire process is analyzed carefully, the code implementation is not difficult:
#include <math.h> #include <queue> #include <deque> #include <vector> #include <stack># Include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #include < iomanip> #include <iostream> #include <algorithm>using namespace std; #define LOWBIT (a) a&-a#define Max (A, B) a>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) int dir[4][2]= {{1,0},{-1,0},{0,1 },{0,-1}};const double eps = 1e-6;const double Pi = ACOs ( -1.0); static const int inf= ~0u>>2;static const int MAXN =1 10;double Map[250][15];int Main () {//freopen ("11.txt", "R", stdin); Freopen ("22.txt", "w", stdout); int n,m,m1,k,i,j; cin>>n; while (n--) {mem (map,0); cin>>m>>m1>>k; if (m1==2) puts ("1.000000"); else {map[1][k]=1; for (i=2; i<=m*2-1; i++) {if (!) ( i%2)) {map[i][1]= (Map[i-1][1])/2,map[i][m1]= (Map[i-1][m1-1])/2; Processing boundary for (j=2; j<m1; j + +) map[i][j]= (Map[i-1][j-1]+map[i-1][j])/2; } else {Map[i][1]=map[i-1][1]+map[i-1][2]/2,map[i][m1-1]=map[i-1] [M1-1]/2+MAP[I-1][M1]; Handle boundary, note the odd row when the boundary of the special case for (j=2; j<m1-1; j + +) map[i][j]= (map[i-1][j]+map[i-1][ J+1])/2; }} cout.setf (ios::fixed); Cout<<setprecision (6) <<map[i-1][1]<<endl; for (j=2; j<m1; j + +) Cout<<setprecision (6) <<map[i-1][j]<<endl; }} return 0;}
Nyoj 374 Pinball II