设为首页 加入收藏

TOP

POJ LAKE COUNTING 2386
2015-07-20 17:29:54 来源: 作者: 【 】 浏览:2
Tags:POJ LAKE COUNTING 2386

基本的dfs的题,看了挑战程序设计这本书对这个算法有了些初步的了解,通过不断的查找不断的更改,找到连在一起的块,提交poj的时候compile error 了两次,第一次没有修改编译器,可能是很久没做题的原因了吧,然后就是纠结是否输入的时候要加循环,导致while 的括号多了一个,我的codeblocks也没发现这个bug,算了,acm的题还是多练吧

#include
#include
using namespace std;
const int MAX_N=101,MAX_M=101;
int n,m;
char field[MAX_N][MAX_M];
void dfs(int x,int y){
field[x][y]='.';
for(int xn=-1;xn<=1;xn++){
for(int yn=-1;yn<=1;yn++){
int xx=xn+x;
int yy=yn+y;
if(0<=xx&&xx<=n&&0<=yy&&yy<=m&&field[xx][yy]=='W')
dfs(xx,yy);
}
}
}
void solve(){
int res=0;
for(int i=0;i for(int j=0;j if(field[i][j]=='W'){
dfs(i,j);
res++;
}
}


}
printf("%d\n",res);
}
int main(){
cin>>n>>m;
// char field[MAX_N][MAX_N+1];
for(int i=0;i for(int j=0;j cin>>field[i][j];
}
}
solve();

return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇zoj 3288 Domination (概率dp) 下一篇Codeforces 112B-Petya and Squar..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)