I want the Thunder Problem description mine has been a popular laboratory of important entertainment games, in the pre-match, brush the problem when tired, sweep a ray often can let the players feel the body and mind of the excitement, after all, the rest of the brush problem, prevent sudden death is the hard truth.
But my luck is always too bad, the key moment two choose a always will point to thunder, indeed minesweeper is also look at the face of the game. Was blown up delirious when, I have no way to distinguish which lattice is ray, can only random point lattice, so please help me to calculate the probability of mine, thank you ~
Of course, in the given mine map, I opened a number lattice and a number of lattice around it (surrounded by a lattice to share an edge or a vertex of the lattice, the surrounding lattice is not all open), and I will only click the next step of the number of the figure is not a bit open lattice;
Section rules for Demining:
Each lattice point can be opened only by numbers, empty grids, and thunder.
On a lattice marked with numbers, the number indicates the total number of mines in the grid around it. Input multiple sets of inputs (<=1000), read to the end of the file;
The first row of each group of data is two integers n and m (2<=n,m<=10), representing the number of rows and columns of the mine map;
Next n lines, each row of M characters represents each row of this mine map.
The figure ' * ' means that there is no dot open lattice, '. ' Represents a lattice around a number that has been opened (representing a number or an empty lattice), and a number (1~8).
The guaranteed number is only one, and the remaining number of squares around it is greater than or equal to the value of the number (that is, to ensure the validity of the input mine map), '. ' Appears only around the numbers. Output a minimal fraction for each set of data, indicating the probability that the lattice is a ray of lightning (if the probability is 1, output 1/1) when the next point opens a lattice around the digital lattice that is not yet opened.
One row of data per set of sample Input
3 3**. 3.***4 5********.***.2.** ...
Sample Output
3/51/1
Author Shang is still a topic of water, I here is a two-dimensional array to make a chessboard, two-dimensional characters to do pieces, so empty the array is a bit simpler
#include <stdio.h>//#include <bits/stdc++.h>#include <string.h>#include<iostream>#include<math.h>#include<sstream>#include<Set>#include<queue>#include<map>#include<vector>#include<algorithm>#include<limits.h>#defineINF 0X3FFFFFFF#defineINF 0x3f3f3f3f#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1#defineLL Long Long#defineULL unsigned long Longusing namespacestd;Chars[ -][ -];inta[ -][ -];inti,j;intn,m;intMain () {intx, y; inti,j; while(cin>>n>>m) {memset (A,0,sizeof(a)); intsum=0; intans; for(i=1; i<=n;i++) { for(j=1; j<=m;j++) {cin>>S[i][j]; if(s[i][j]=='*') {A[i][j]=1; } if(s[i][j]=='.') {A[i][j]=2; } Else if(s[i][j]>='1'&&s[i][j]<='8') {A[i][j]=3; Ans=s[i][j]-'0'; X=i; Y=J; } } } for(i=x-1; i<=x+1; i++) { for(j=y-1; j<=y+1; J + +) { if(a[i][j]==1) {sum++; } //cout<<a[i][j]; } //cout<<endl; } //cout<<sum<<endl;COUT<<ANS/__GCD (Sum,ans) <<"/"<<SUM/__GCD (Sum,ans) <<Endl; } return 0;}
2015 Suzhou University ACM-ICPC Training Team Tryouts (2) 1002