The point to be aware of is not the n*n matrix, the column should be separately
DFS, please.
#include <bits/stdc++.h>#define LL Long Longusing namespace STD;Const intMAXN =1e6;intN,m;Charmp[ -][ -];intAnsvoidDfs_r (intXintY) {if(x >=0&& x < n && y >=0&& y < M && (mp[x][y] = =' R '|| Mp[x][y] = =' G ')) {if(Mp[x][y] = =' G ') Mp[x][y] =' B ';ElseMp[x][y] ='. '; Dfs_r (x1, Y1); Dfs_r (x+1, y+1); }return;}voidDfs_b (intXintY) {if(x >=0&& x < n && y >=0&& y < M && (mp[x][y] = =' B '|| Mp[x][y] = =' G ')) {if(Mp[x][y] = =' G ') Mp[x][y] =' R ';ElseMp[x][y] ='. '; Dfs_b (x+1, Y1); Dfs_b (x1, y+1); }return;}intMain () {#ifdef XXZ //freopen ("OUT.txt", "w", stdout);Freopen ("In.txt","R", stdin);#endif //XXZ intTscanf("%d", &t); while(t--) {scanf("%d", &n); for(inti =0; I < n; i++)scanf('%s ', Mp[i]);intAns =0; m =strlen(mp[0]); for(inti =0; I < n; i++) { for(intj =0; J < M; J + +) {if(Mp[i][j] = =' R ') {Dfs_r (i,j); ans++; }Else if(Mp[i][j] = =' B ') {dfs_b (i,j); ans++; }Else if(Mp[i][j] = =' G ') {Dfs_r (i,j); MP[I][J] =' B '; Dfs_b (I,J); Ans + =2; } } }printf("%d\n", ans); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
2015 Multi-School joint training third session painter (hdu5319)