/*
概率计算:按时间为阶段,每个点由上一阶段周围的四个点来维护。
注意事项:1.时间O(N^3*T),在问题的边缘时间,所以打表计算。
2.关于概率的求解,如果遇到就结束了,所以向后走就说明
之前没有碰到,所以不用前面的碰到的概率计算后面的值。
*/
View Code
1 #include <stdio.h>
2 #include <string.h>
3
4 double answ[ 51 ] = {
5 0.0000,0.6667,0.0000,0.4074,0.0000,
6 0.3361,0.0000,0.2928,0.0000,0.2629,
7 0.0000,0.2407,0.0000,0.2233,0.0000,
8 0.2092,0.0000,0.1975,0.0000,0.1875,
9 0.0000,0.1789,0.0000,0.1714,0.0000,
10 0.1648,0.0000,0.1589,0.0000,0.1536,
11 0.0000,0.1487,0.0000,0.1443,0.0000,
12 0.1403,0.0000,0.1366,0.0000,0.1332,
13 0.0000,0.1300,0.0000,0.1270,0.0000,
14 0.1243,0.0000,0.1217,0.0000,0.1192};
15
16 /*
17
18 double maps[ 100 ][ 100 ][ 100 ];
19 short dxdy[ 4 ][ 2 ] = {1,0,0,1,-1,0,0,-1};
20
21 void madelist() // 打表程序
22 {
23 for ( int n = 1 ; n < 100 ; n += 2 ) {
24 double sum = 0.0;
25 memset( maps, 0, sizeof( maps ) );
26 maps[ 0 ][ n/2 ][ n/2 ] = 1.0;
27 for ( int t = 0 ; t < n ; ++ t )
28 for ( int i = 0 ; i < n ; ++ i )
29 for ( int j = 0 ; j < n ; ++ j )
30 for ( int k = 0 ; k < 4 ; ++ k ) {
31 int x = i+dxdy[ k ][ 0 ];
32 int y = j+dxdy[ k ][ 1 ];
33 if ( x > 0 && x < n-1 && y > 0 && y < n-1 )
34 maps[ t+1 ][ i ][ j ] += 0.25*maps[ t ][ x ][ y ];
35 else if ( ( x == 0 && y == 0 ) || ( x == 0 && y == n-1 ) ||
36 ( x== n-1 && y == 0 ) || ( x == n-1 && y == n-1 ) )
37 maps[ t+1 ][ i ][ j ] += 0.5*maps[ t ][ x ][ y ];
38 else maps[ t+1 ][ i ][ j ] += 1.0/3*maps[ t ][ x ][ y ];
39 if ( i == n/2 && j == t ) {
40 sum += maps[ t+1 ][ i ][ j ];
41 maps[ t+1 ][ i ][ j ] = 0.0;
42 }
43 }
44 printf("%.4lf,",sum);
45 }
46 }
47 */
48
49 int main()
50 {
51 int m;
52 while ( ~scanf("%d",&m) )
53 printf("%.4lf\n",answ[ m/2 ]);
54 return 0;
55 }