Main topic:
Placing as many robots as possible in the open space, the robot fired bullets in 4 directions up and down, bullets could cross the grass, but not through the walls.
Two robots between the bullets to ensure that they do not interfere with each other, to find the maximum number of robots can be placed
The location of each robot is determined, so that the corresponding horizontal and vertical bullets can reach the open space is all covered.
We're going to mark the same label in the area where we can connect to a space.
such as O*o#o, can be labeled as 10102 because the grass in the middle of the 1,3 open space does not affect the passage of bullets
In the same vein, the vertical can be connected to a block of vacant space marked with the same label.
Then you can set up a two-part graph match that reaches the vertical horizontally.
Each successful match is equivalent to placing a fort at the intersection.
This translates into the maximum number of matches.
1#include <cstdio>2#include <cstring>3 4 using namespacestd;5 Const intN = -;6 7 CharStr[n][n];8 intN, M, Xs[n][n], ys[n][n], idx, idy;//The IDX record is the maximum label for the behavior axis, and the Idy is the maximum number of columns to be listed as axes9 intCx[n*n], Cy[n*n], visy[n*N];Ten BOOLG[n*n][n*n];//int is 4 bytes, mle,bool a byte with int One A intDfsintu) - { - for(intv =1; V<=idy; v++){ the if(G[u][v] &&!Visy[v]) { -VISY[V] =1; - if(Cy[v] = =-1||DFS (Cy[v])) { -Cx[u] =v; +CY[V] =u; - return 1; + } A } at } - return 0; - } - - intMaxmatch () - { inmemset (CX,-1,sizeof(CX)); -memset (CY,-1,sizeof(CY)); to intAns =0; + for(intI=1; I<=idx; i++){ - if(Cx[i] = =-1){ thememset (Visy,0,sizeof(Visy)); *Ans + =DFS (i); $ }Panax Notoginseng } - returnans; the } + A intMain () the { + //freopen ("a.in", "R", stdin); - intT, CAS =0; $scanf"%d", &T); $ while(t--) - { -scanf"%d%d", &n, &m); the for(inti =0; I<n; i++) -scanf"%s", Str[i]);Wuyi the //Make the same number of positions that each line of Fort can reach - intID =1, flag =0; Wu for(intI=0; I<n; i++){ - if(flag) flag =0, id++; About for(intj =0; J < M; J + +){ $ if(Str[i][j] = ='o') -XS[I][J] = id, idx = ID, flag =1; - Else if(Str[i][j] = ='#') -Flag =0, id++; A } + } the - //Make the same number of positions that each turret can reach $ID =1, flag =0; the for(intI=0; I<m; i++){ the if(flag) flag =0, id++; the for(intj =0; J < N; J + +){ the if(Str[j][i] = ='o') -Ys[j][i] = id, Idy = ID, flag =1; in Else if(Str[j][i] = ='#') theFlag =0, id++; the } About } the the //construct two-part diagram theMemset (G,0,sizeof(g)); + for(inti =0; I<n; i++) - for(intj =0; J<m; J + +){ the if(Str[i][j] = ='o')BayiG[XS[I][J]][YS[I][J]] =true; the } theprintf"Case :%d\n%d\n", ++CAs, Maxmatch ()); - } - return 0; the}
ZOJ 1654 Place the Robots