Nails and pellets

Source: Internet
Author: User

"Title description"

There is a triangular plank, vertical upright, with n (n+1)/2 nails on it, and (n+1) a lattice (when n=5 1). The distance between each nail and the surrounding nail is equal to D, and the width of each lattice is equal to D, and each lattice in addition to the leftmost and most right side of the grid is facing the bottom row of nails.

Let a small ball center with a diameter of slightly less than D is on the top of the nail on the board free roll, the ball every hit a nail may fall to the left or the right (1/2 probability each), and the center of the ball will be facing the next nail will be met. Example 2 is a possible path for the ball.

The problem now is to calculate the probability of the ball falling in a lattice numbered m after unplugging certain nails. Suppose the bottom row of nails will not be pulled out. Example 3 is a possible path of a small ball after some nails are pulled out.

"Input description"

The 1th behavior is integer n (2<=n<=50).

The following n lines are the information from top to bottom n rows of nails on the board, and each line ' * ' indicates that the nail is still in, '. ' means the nail is removed (the nail in the bottom row will not be pulled out), note that the space character may appear anywhere in this n row.

"Output description"

A total of n+1 lines, each line is a fraction of both (0 written 0/1), for the ball falls in the number 0 to the number of n this n+1 lattice of probability m.

Definition of both the fraction: A/b is both an approximate fraction when and only if A and B are positive integers and a and b do not have a public factor greater than 1.

"Sample Input"

4

*

* *

* . *

* * * *

"Sample Output"

1/16

1/8

5/8

1/8

1/16

"Data range and Tips"

(2<=N<=50)

source code: #include<iostream>using namespacestd;Long Longn,i1[ A][ A]={0},i2[ A][ A]={0};//long long can even explode! And with Cin and cout!. BOOLf[ A][ A]={0};voidX1 (Long Long&AMP;X1,Long Long&y1,Long LongX2,Long Longy2)//the method of dividing the pit father. {    if(!y2)return; if(x2&1) Y2=y2<<1; ElseX2=x2>>1; if(!y1) {X1=x2; Y1=Y2; }    Else    {        Long LongT1=y1,t2=Y2;  while(t1%T2) {            Long Longt=T1; T1=T2; T2=t%T2; }        Long Longt= (Y1*Y2)/T2; T1=x1* (t/y1) +x2* (t/y2); T2=T; X1=T1; Y1=T2;  while(t1%T2) {            Long Longt=T1; T1=T2; T2=t%T2; }        if(! (x1%T2)) {X1/=T2; Y1/=T2; }    }}intMain () {CIN>>N;  for(intA=1; a<=n;a++)       for(intb=1; b<=a;b++)      {          CharT; CIN>>T;  while(t!='*'&&t!='.') Cin>>T; if(t=='*') F[a][b]=true; }     for(intA=1; a<=n+1; a++) F[n+1][a]=true; if(f[1][1]) i1[1][1]=i2[1][1]=1; Else    {        intt1=3, t2=2;  while(!f[t1][t2]&& (t1+2) <=n+1) {T1+=2; T2++; }        if(F[t1][t2]) x1 (i1[t1][t2],i2[t1][t2],2,1); }     for(intA=1; a<n;a++)       for(intb=1; b<=a;b++)      {        if(f[a+1][b]) x1 (i1[a+1][b],i2[a+1][b],i1[a][b],i2[a][b]); Else        {            intt1=a+3, t2=b+1;  while(!f[t1][t2]&& (t1+2) <=n+1) {T1+=2; T2++; }            if(F[t1][t2]) x1 (i1[t1][t2],i2[t1][t2],i1[a][b],i2[a][b]); }        if(f[a+1][b+1]) x1 (i1[a+1][b+1],i2[a+1][b+1],i1[a][b],i2[a][b]); Else        {            intt1=a+3, t2=b+2;  while(!f[t1][t2]&& (t1+2) <=n+1) {T1+=2; T2++; }            if(F[t1][t2]) x1 (i1[t1][t2],i2[t1][t2],i1[a][b],i2[a][b]); }      }     for(intA=1; a<=n;a++) {X1 (i1[n+1][a],i2[n+1][a],i1[n][a],i2[n][a]); X1 (I1[n+1][a+1],i2[n+1][a+1],i1[n][a],i2[n][a]); }     for(intA=1; a<=n+1; a++)      if(i1[n+1][a]) cout<<i1[n+1][a]<<"/"<<i2[n+1][a]<<Endl; Elsecout<<"0/1"<<Endl; return 0;} //The whole thing is bad for the water to finish the problem. 

Nails and pellets

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.