标签:include mes c++ style connect ons png mamicode return
AC_Code:
1 #include <bits/stdc++.h> 2 #include <iostream> 3 #include <cstring> 4 #include <string> 5 using namespace std; 6 typedef long long ll; 7 const int maxn = 2005; 8 int mp[maxn][maxn]; 9 int tot; 10 int n,m; 11 12 void make(int i,int j,char ch) 13 { 14 int a,b,c,d; 15 if( ch==‘.‘ ) a=0,b=0,c=0,d=0; 16 if( ch==‘/‘ ) a=0,b=-1,c=-1,d=0; 17 if( ch==‘\\‘) a=-1,b=0,c=0,d=-1; 18 mp[i*2-1][j*2-1]=a; mp[i*2-1][j*2]=b; mp[i*2][j*2-1]=c; mp[i*2][j*2]=d; 19 } 20 21 int dx[4]={0,0,-1,1}; 22 int dy[4]={1,-1,0,0}; 23 24 void dfs(int x,int y){ 25 mp[x][y] = tot; 26 for(int i=0;i<4;i++){ 27 int xx = x+dx[i]; 28 int yy = y+dy[i]; 29 if( xx>=0 && xx<=n && yy>=0 && yy<=m && !mp[xx][yy] ){ 30 dfs(xx,yy); 31 } 32 } 33 } 34 35 int main() 36 { 37 scanf("%d%d",&n,&m); 38 for(int i=1;i<=n;i++){ 39 for(int j=1;j<=m;j++){ 40 char ch; 41 cin>>ch; 42 make(i,j,ch); 43 } 44 } 45 46 n=n*2+1; 47 m=m*2+1; 48 tot=0; 49 for(int i=0;i<=n;i++){ 50 for(int j=0;j<=m;j++){ 51 if(mp[i][j]==0 ){ 52 tot++; 53 dfs(i,j); 54 } 55 } 56 } 57 printf("%d\n",tot-1); 58 return 0; 59 }
标签:include mes c++ style connect ons png mamicode return
原文地址:https://www.cnblogs.com/wsy107316/p/12242359.html