标签:cte algo memory number rac lower count str limit
Time limit1000 ms
Memory limit65536 kB
Input
Output
Sample Input
10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W.
Sample Output
3
Hint
#include<iostream> #include<algorithm> #include<cstring> #include<sstream> #include<cmath> #include<cstdlib> #include<queue> using namespace std; #define PI 3.14159265358979323846264338327950 int N,M; const int MAX_N=103; char field[MAX_N][MAX_N]; void dfs(int x,int y) { field[x][y]=‘.‘; for(int dx=-1;dx<=1;dx++) { for(int dy=-1;dy<=1;dy++) { int nx=x+dx,ny=y+dy; if(0<=nx && nx<N && 0<=ny && ny<M && field[nx][ny]==‘W‘) dfs(nx,ny); } } return ; } void solve() { int res =0; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { if(field[i][j]==‘W‘) { dfs(i,j); res++; } } } printf("%d\n",res); } int main() { cin>>N>>M; for(int i=0;i<N;i++) for(int j=0;j<M;j++) cin>>field[i][j]; solve(); }
标签:cte algo memory number rac lower count str limit
原文地址:https://www.cnblogs.com/smallhester/p/9499097.html