poj2386----简单dfs,a一送一
来源:互联网 发布:淘宝男内裤 买家秀 编辑:程序博客网 时间:2024/06/03 23:00
/*poj2386 求有几个水坑*/#include<stdio.h>#include<iostream>char ans[110][110];int n, m;int cnt;int dx[10] = {-1, 0, 1, -1, 1, -1, 0, 1};int dy[10] = {1, 1, 1, 0, 0, -1, -1, -1};void dfs(int x, int y){ ans[x][y] = '.'; for(int i=0; i<8; i++) { int tx = x + dx[i]; int ty = y + dy[i]; if(tx>=0 && tx<n && ty>=0 && ty<m && ans[tx][ty]=='W') { dfs(tx, ty); } }}void fun(){ cnt = 0; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if(ans[i][j] == 'W') { cnt++; dfs(i, j); } } } printf("%d\n", cnt); }int main(){ while(scanf("%d %d", &n, &m) != EOF) { getchar(); for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { scanf("%c", &ans[i][j]); } getchar(); } fun(); } return 0; }
a一送一:poj3620
/*poj3620 求最大的水坑*/ #include<iostream>#include<stdio.h>int n, m, k;int ans[110][110];int dx[5] = {0, 1, 0, -1};int dy[5] = {1, 0, -1, 0};int tmp;void dfs(int x, int y){ ans[x][y] = 0; tmp++; for(int i=0; i<4; i++) { int tx = x + dx[i]; int ty = y + dy[i]; if(tx>=0 && tx<n && ty>=0 && ty<m && ans[tx][ty]) { dfs(tx, ty) ; } } }void fun(){ int cnt = 0; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { tmp=0; if(ans[i][j]) { dfs(i, j); if(tmp > cnt) cnt = tmp; } } } printf("%d\n", cnt); }int main(){ int a, b; while(scanf("%d %d %d", &n, &m, &k) != EOF) { for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { ans[i][j] = 0; } } for(int i=0; i<k; i++) { scanf("%d %d", &a, &b); ans[a-1][b-1] = 1; } fun(); } return 0; }
a一送一:poj3620
- poj2386----简单dfs,a一送一
- 简单dfs--poj2386
- POJ2386-简单BFS/DFS
- POJ2386 Lake Counting简单dfs
- poj2386 Lake Counting(简单DFS)
- poj2386-dfs
- poj2386 DFS
- POJ2386:Lake Counting(DFS)
- poj2386 Lake Counting DFS
- POJ2386 Lake Counting(DFS)
- POJ2386 Lake Counting 【DFS】
- poj2386(dfs)
- poj2386水洼dfs
- poj2386 (DFS)
- POJ2386经典DFS深搜
- POJ2386 Lake Counting (dfs)
- POJ2386 Lake Counting(dfs)
- poj2386 Lake Counting【DFS】
- Ubuntu12.04下eclipse提示框黑色背景色的修改方法
- nexus 7 入手小记
- (待整理)linux网络设置笔记整理
- BouncycastleMessageDecryptionVerificationHandler.java
- 黑马程序员_有关构造方法的一道面试题
- poj2386----简单dfs,a一送一
- 产品设计:Android应用-开发技术【数据缓存】
- GIT帮助文档翻译之git-add
- windows下利用OpenVPN搭建VPN服务器
- POJ 2828 Buy Tickets 线段树 单点更新
- 树莓派(raspberry pi)学习1: 入门,试用虚拟机
- cygwin下hadoop搭建
- Codeforces 243C
- 二元操作符重载