Test instructions is very understood, roughly is three kinds of colors, red and blue together will turn green, give an end state matrix, ask from the original state to the final state at least draw a few strokes? Draw according to certain rules
The idea is to remember red for 1, Blue is 2, Green is 3, first walk green, for each piece of green to delete, each found a piece of green, first set it to zero, and then the main diagonal and it next to the red or green-1, the diagonal and it next to the blue or green -2,ans+2; know all the green so far. Then traverse the remaining red and blue, red block on the main diagonal and it next to the red-1 (including IT) ans+1, the green diagonal and it next to the blue-2 (including IT) ans+1. The final output of ans can be.
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;intn,m;intg[Wuyi][Wuyi];intans=0;voidDfs_1 (intXintY//Upper left{ while(g[x][y]==1|| g[x][y]==3) { //puts ("1");g[x][y]--; X--; Y--; }}voidDfs_2 (intXintY//Lower Right{ while(g[x][y]==1|| g[x][y]==3) { //puts ("1");g[x][y]--; X++; Y++; }}voidDfs_3 (intXintY//Lower left{ while(g[x][y]==2|| g[x][y]==3) { //puts ("1");g[x][y]-=2; X++; Y--; }}voidDfs_4 (intXintY//Top Right{ while(g[x][y]==2|| g[x][y]==3) { //puts ("1");g[x][y]-=2; X--; Y++; }}intMain () {intT; scanf ("%d",&t); while(t--) {ans=0; Memset (g,0,sizeof(g)); scanf ("%d",&N); for(intI=1; i<=n;i++) { Charcc[Wuyi]; Memset (CC,' /',sizeof(cc)); scanf ("%s", CC); M=strlen (CC); for(intj=0; j<m;j++) { if(cc[j]=='R') g[i][j+1]=1; if(cc[j]=='B') g[i][j+1]=2; if(cc[j]=='G') g[i][j+1]=3; } } for(intA=1; a<=n;a++) { for(intb=1; b<=m;b++) { if(g[a][b]==3) {G[a][b]=0; Dfs_1 (A-1, B-1); Dfs_2 (A+1, B +1); Dfs_3 (A+1, B-1); Dfs_4 (A-1, B +1); Ans+=2; } } } for(intC=1; c<=n;c++) { for(intD=1;d <=m;d++) { if(g[c][d]==1) {G[c][d]=0; Dfs_1 (c-1, d1); Dfs_2 (c+1, d+1); Ans++; } Else if(g[c][d]==2) {G[c][d]=2; Dfs_3 (c+1, d1); Dfs_4 (c-1, d+1); Ans++; }}} printf ("%d\n", ans); }}
hdu5319 Simple Simulation