- 送给圣诞夜的极光
- 2016-07-17 16:27:15 @
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int map[110][110]={0};
int visit[110][110]={0};
int n,m,ans;
int count =0;
void dfs(int r,int c){
if(r==n&&c==m){
count ++;
return ;
}
visit[r][c]=1;
if(visit[r-1][c]==0&&map[r-1][c]==1){
dfs(r-1,c);
}
if(visit[r-2][c]==0&&map[r-2][c]==1){
dfs(r-2,c);
}
if(visit[r+1][c]==0&&map[r+1][c]==1){
dfs(r+1,c);
}
if(visit[r+2][c]==0&&map[r+2][c]==1){
dfs(r+2,c);
}
if(visit[r][c-1]==0&&map[r][c-1]==1){
dfs(r,c-1);
}
if(visit[r][c-2]==0&&map[r][c-2]==1){
dfs(r,c-2);
}
if(visit[r][c+1]==0&&map[r][c+1]==1){
dfs(r,c+1);
}
if(visit[r][c+2]==0&&map[r][c+2]==1){
dfs(r,c+2);
}
if(visit[r-1][c-1]==0&&map[r-1][c-1]==1){
dfs(r-1,c-1);
}
if(visit[r-1][c+1]==0&&map[r-1][c+1]==1){
dfs(r-1,c+1);
}
if(visit[r+1][c+1]==0&&map[r+1][c+1]==1){
dfs(r+1,c+1);
}
if(visit[r+1][c-1]==0&&map[r+1][c-1]==1){
dfs(r+1,c-1);
}
return;
}
int main (){
cin>>n>>m;
int i,j;
char a;
for(i=2;i<=n+1;i++){
for(j=2;j<=m+1;j++){
cin>>a;
if(a=='#') map[i][j]=1;
}
}
for(i=2;i<=n+1;i++){
for(j=2;j<=m+1;j++){
if(map[i][j]==1&&visit[i][j]==0){
ans++;
dfs(i,j);
}
}
}
cout <<ans <<endl;
return 0;
}悪,为什么只有60分?哭...晕...在...厕...所
3 条评论
-
gusc LV 6 @ 2017-01-23 13:34:33
TN屏的悲剧
-
2016-10-18 08:10:41@
我勒个去
-
2016-07-17 16:30:29@
悪...
- 1