Uva 11884 - A Shooting Game
你为何这么叼!
Time limit: 1.000 seconds
A and B are playing a shooting game on a battlefield consisting of square-shaped unit blocks. The blocks are occupying some consecutive columns, and the perimeter of the figure equals the perimeter of its minimal bounding box. The figure (a) below is a valid battlefield, but (b) and (c) are not, because in (b), there is an empty column; in (c), the perimeter of figure is 14, but the perimeter of the bounding box (drawn with dashed lines) is 12. With the help of gravity, each block is either located on another block, or sitting on the ground. To make the battlefield look more exciting, it must not be a perfect rectangle (i.e. it is not allowed that every column has the same height)

Here is the rule of the game:
- A and B shoot by turn. A starts first.
- Before shooting, the player first select one row with at least one block, and one of the two directions "left" and "right", then shoot at this row along that direction. The power of the shoot is one of 1, 2 or 3, each with probability of 1/3. The power of shoot is the number of blocks (not necessarily consecutive) that can be destroyed in this shoot. If the total number of blocks on this row is less than the power of shoot, then all the blocks on this row is destroyed. For example, if the player chooses to shoot the 3rd row from the bottom, with direction "right", power 2, and there are 4 blocks on this row, then the left-most two blocks are destroyed.
- After each shoot, blocks in the air fall down vertically. The next player cannot shoot before all the blocks stop falling.
- Realize that the intermediate battlefields do not have to follow the constraints for starting battlefields. For example, it could happens some situations looking as figures (b) or (c), and then, if the power is p, the leftmost/rightmost p blocks of columns which contain a block in this row are destroyed (skipping empty positions).
- He who destroys the last block wins.
Assume the starting battlefield is
. According to rule 1, A shoots first. The table below shows three (not all) possible outcomes of the first shot:
| Row(from bottom) | Direction | Power | Befrore Falling | Stable |
| 2 | Left | 1 | ![]() |
(Same as left) |
| 1 | Left | 2 | ![]() |
![]() |
| 1 | Right | 3 | ![]() |
![]() |
Assume Alice and Bob are both very clever (always follows the strategy that maximizes the probability he/she wins), what is the probability that Alice wins?
Input
There will be at most 25 test cases, each with two lines. The first line is a single integer n ( 1
n
6), the number of columns. The second line contains n integers h1, h2, ..., hn ( 1
hi
6), the heights of the columns from left to right. The battlefield is guaranteed to satisfy the restrictions in the problem (perimeter of figure equals that of the minimal bounding box, and is not a perfect rectangle). Input is terminated by n = 0.
Output
For each test case, print a single line, the probability that A wins, to six decimal points.
Sample Input
3 2 1 1 0
Sample Output
0.555556
Problemsetter: Rujia Liu, Special Thanks: Yiming Li, Tanaeem M Moosa & Sohel Hafiz
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <stdio.h> 3 #include <string.h> 4 #include <iostream> 5 #include <algorithm> 6 #include <vector> 7 #include <queue> 8 #include <set> 9 #include <map> 10 #include <string> 11 #include <math.h> 12 #include <stdlib.h> 13 #include <time.h> 14 using namespace std; 15 #define maxn 101 16 #define INF 0x7fffffff 17 const double eps=1e-8; 18 int n; 19 int a[maxn]; 20 double dp[7][7][7][7][7][7]; 21 double win(int x0,int x1,int x2,int x3,int x4,int x5){ 22 double res=0.0,tmp; 23 if(dp[x0][x1][x2][x3][x4][x5]>eps)return dp[x0][x1][x2][x3][x4][x5]; 24 if(x0+x1+x2+x3+x4+x5==0)return 0; 25 for(int i=1;i<=6;i++){ 26 tmp=0.0; 27 int k,v0,v1,v2,v3,v4,v5; 28 for(int j=1;j<=3;j++){ 29 k=j;v0=x0;v1=x1;v2=x2;v3=x3;v4=x4;v5=x5; 30 if(v0>=i&&k)v0--,k--; 31 if(v1>=i&&k)v1--,k--; 32 if(v2>=i&&k)v2--,k--; 33 if(v3>=i&&k)v3--,k--; 34 if(v4>=i&&k)v4--,k--; 35 if(v5>=i&&k)v5--,k--; 36 if(k==j)continue; 37 tmp+=1.0/3*(1.0-win(v0,v1,v2,v3,v4,v5)); 38 } 39 if(res<tmp)res=tmp; 40 tmp=0.0; 41 for(int j=1;j<=3;j++){ 42 k=j;v0=x0;v1=x1;v2=x2;v3=x3;v4=x4;v5=x5; 43 if(v5>=i&&k)v5--,k--; 44 if(v4>=i&&k)v4--,k--; 45 if(v3>=i&&k)v3--,k--; 46 if(v2>=i&&k)v2--,k--; 47 if(v1>=i&&k)v1--,k--; 48 if(v0>=i&&k)v0--,k--; 49 if(k==j)continue; 50 tmp+=1.0/3*(1.0-win(v0,v1,v2,v3,v4,v5)); 51 } 52 if(res<tmp)res=tmp; 53 } 54 return dp[x0][x1][x2][x3][x4][x5]=res; 55 } 56 int main(){ 57 while(scanf("%d",&n)&&n){ 58 memset(a,0,sizeof a); 59 memset(dp,0,sizeof dp); 60 for(int i=0;i<n;i++)scanf("%d",&a[i]); 61 printf("%.6lf\n",win(a[0],a[1],a[2],a[3],a[4],a[5])); 62 } 63 return 0; 64 }





浙公网安备 33010602011771号