Test instructions: give you a map to find the number of unicom blocks.
Exercises
for (all ' @ ' points not yet marked)
The Edge Dfs edge is in the VIS array tag ID until DFS cannot continue.
Output ID and May;
AC Code:
#define_crt_secure_no_warnings#include"stdio.h"#include<stdio.h>#include<algorithm>#include<string>#include<vector>#include<list>#include<Set>#include<iostream>#include<string.h>#include<queue>#include<string>#include<sstream>using namespacestd;Const intMAXN = -+5;stringMAP[MAXN];intans;intIDX[MAXN][MAXN];intN, M;voidDfsintRintCintID) {if(r<0|| c<0|| r>=n| | c>=m| | MAP[R][C] = ='*'|| IDX[R][C])return; IDX[R][C]=ID; for(intdr=-1;d r<=1;d r++) for(intDC =-1; DC <=1; Dc++) if(dr| | DC) DFS (r + DR, C +dc,id);}intMain () { while(Cin >> N >>m) {if(n = =0&& m = =0) Break; Ans=0; memset (IDX,0,sizeof(IDX)); for(inti =0; I < n; i++) {cin>>Map[i]; } for(inti =0; I < n; i++) for(intj =0; J < M; J + +) if(Idx[i][j] = =0&& Map[i][j] = ='@') Dfs (I, J, + +)ans); cout<< ans<<Endl; } return 0;}
"Purple book" Oil deposits UVA-572 Dfs Beg Unicom block