poj 2386
来源:互联网 发布:zach king 知乎 编辑:程序博客网 时间:2024/05/23 12:45
#include <stdio.h>#include <stdlib.h>char a[101][101];int N,M;void dfs(int x,int y){ int i,j,dx,dy; a[x][y]='.'; for(i=-1;i<2;i++){ for(j=-1;j<2;j++) { dx=x+i; dy=y+j; if(dx>=0&&dx<N&&dy>=0&&dy<M&&a[dx][dy]=='W') dfs(dx,dy); } } return ;}int main(){ int i,j,ans=0; scanf("%d%d",&N,&M); for(i=0;i<N;i++) //for(j=0;j<M;j++) scanf("%s",a[i]); for(i=0;i<N;i++){ for(j=0;j<M;j++){ if(a[i][j]=='W'){ dfs(i,j); ans++; } } } printf("%d\n",ans); return 0;}今天学习dfs,然后有这个例题,就自己写了一遍,加油吧。
0 0
- POJ 2386
- POJ 2386
- POJ 2386
- POJ 2386
- poj 2386
- poj 2386
- POJ 2386
- POJ-2386
- POJ 2386
- poj 2386
- poj 2386
- POJ 2386
- POJ 2386
- POJ 2386
- POJ 2386
- POJ 2386
- POJ 2386
- poj 2386 Lake Counting
- UISearchDisplayController 与 UISearchBar 在IOS7的问题
- Camera显示之Hal层的适配(二)
- SNAT和DNAT
- Cassandra源代码阅读笔记
- Visual Studio 2012 调试.net framework4.5源码
- poj 2386
- Log4Net使用指南 .
- tomcat7.0运行错误
- UML类图——统一建模语言
- assert()
- HTTP报文
- 转个NX的 数据库操作类
- HttpURLConnection
- 黑马程序员——java开发经验