POJ 2386 题解】的更多相关文章

Lake Counting 描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Fa…
链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace std; ,MAX_N=; char a[MAX_N][MAX_M]; int N,M; //现在位置 (x,y) void dfs(int x,int y){ a[x][y]='.'; //将现在所在位置替换为'.',即旱地 ;dx<=;dx++){ //循环遍历连通的8个方向:上.下.左.右.左上.左下…
地址 http://poj.org/problem?id=2386 <挑战程序设计竞赛>习题 题目描述Description Due to recent rains, water has pooled in various places in Farmer John’s field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each squa…
简单的深度搜索就能够了,看见有人说什么使用并查集,那简直是大算法小用了. 由于能够深搜而不用回溯.故此效率就是O(N*M)了. 技巧就是添加一个标志P,每次搜索到池塘,即有W字母,那么就觉得搜索到一个池塘了,P值为真. 搜索过的池塘不要反复搜索,故此,每次走过的池塘都改成其它字母.如'@',或者'#',随便一个都能够. 然后8个方向搜索. #include <stdio.h> #include <vector> #include <string.h> #include…
Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer…
http://poj.org/problem?id=2386 这个题目与那个POJ 1562几乎是差不多的,只不过那个比这个输入要复杂一些 #include <stdio.h> #include <string.h> #include <iostream> using namespace std; ][]; int dps(int i,int j) { ][j-]=='W') { str[i-][j-]='#'; dps(i-,j-); } ][j]=='W') { s…
http://poj.org/problem?id=2386 http://acm.hdu.edu.cn/showproblem.php?pid=1241 求有多少个连通子图.复杂度都是O(n*m). #include <cstdio> ][]; int n,m; void dfs(int x,int y) { ;i<=;i++) ;j<=;j++) //循环遍历8个方向 { int xx=x+i,yy=y+j; &&xx<n&&yy>=…
Lake Counting(POJ No.2386) Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W')…
http://poj.org/problem?id=2386 题目大意: 有一个大小为N*M的园子,雨后积起了水.八连通的积水被认为是连接在一起的.请求出院子里共有多少水洼? 思路: 水题~直接DFS,DFS过程把途中表示水洼的W改为'.',看DFS了几次即可. #include<cstdio> #include<cstring> const int MAXN=100+10; char map[MAXN][MAXN]; int n,m; void dfs(int x,int y)…
题目 题意: $ yyf $ 一开始在 $ 1 $ 号节点他要通过一条有 $ n $ 个地雷的道路,每次前进他有 $ p $ 的概率前进一步,有 $ 1-p $ 的概率前进两步,问他不领盒饭的概率. 对于这道题我们可以考虑 $ dp $ ,我们可以设计状态 $ f[i] $ 表示安全通过 $ i $的概率,那么我们可以得到状态转移方程 $ f[i]=p* f[i-1]+(1-p)* f[i-2] $ $ f[x_i]=0 $ 然后我们可以看到 $ x \in [1, 100000000] $如果…