Nyoj Pinball II (mathematical simulation)

Source: Internet
Author: User

Pinball II time limit: +Ms | Memory Limit:65535Kb
Describe

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). It is now known that total2 * n-1line pipe, sectionILine hasAia pipe, ifIis odd, thenAiequalsm, ifIis an even number,Aiequalsm-1. Ball from the first1Line No.ka 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
Source
Gdut School Race
Uploaded by

Acm_ Li Rubing

Idea: The pinball version as a n*2 figure

0 1 2 3 4 5 6 7 8 9

0

1 * * *

2 1

3 * *

4 2 2

5 * * *

6

#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <    String.h>using namespace std;double dp[205][25];int main () {int t;    cin>>t;        while (t--) {int n,m,k;        cin>>n>>m>>k;        Memset (Dp,0,sizeof (DP));        Dp[2][2*k]=1; for (int i=2; i<2*n; i++) {if (i%2==0)//Even regardless of boundary condition {for (int j=2; j<=2*m-2; j+                    =2) {dp[i+1][j-1]+=dp[i][j];                DP[I+1][J+1]+=DP[I][J]; }} else//odd consider boundary {dp[i+1][2]=dp[i][1]*2;//left boundary dp[i+1][2*m- 2]=dp[i][2*m-1]*2;//right boundary for (int j=3; j<=2*m-3; j+=2) {Dp[i+1][j-1]+=d                    P[I][J];                DP[I+1][J+1]+=DP[I][J];        }}} double sum=0;   for (int i=2; i<=2*m-2; i+=2) sum+=dp[2*n][i];     for (int i=2; i<=2*m-2; i+=2) printf ("%.6lf", dp[2*n][i]/sum);    printf ("\ n"); }}



Nyoj Pinball II (mathematical simulation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.