杭电1241 Oil Deposits
来源:互联网 发布:linux 创建文件 编辑:程序博客网 时间:2024/05/17 09:16
#include<iostream>
#include<string>
using namespace std;
const int maxn = 105;
string map[maxn];
int row, column, res;
void dfs(int x, int y)
{//深度搜索
map[x][y] = '*';//遍历过的做上记号
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int nx = x + dx;
int ny = y + dy;
if (0 <= nx&&nx < row && 0 <= column&&ny < column&&map[nx][ny] == '@')
dfs(nx, ny);
}//*米 3*3 =9 但是map[x][y]本身被标记了,所以是八个方向
}
return;
}
void solve()
{
res = 0;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
if (map[i][j] == '@') {
dfs(i,j);
res++;
}
}
}
}
int main()
{
//freopen("data.in","r",stdin);
while (cin >> row >> column, row || column)
{
for (int i = 0; i < row; i++)
cin >> map[i];
solve();
cout<<res<<endl;
}
return 0;
}
#include<string>
using namespace std;
const int maxn = 105;
string map[maxn];
int row, column, res;
void dfs(int x, int y)
{//深度搜索
map[x][y] = '*';//遍历过的做上记号
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int nx = x + dx;
int ny = y + dy;
if (0 <= nx&&nx < row && 0 <= column&&ny < column&&map[nx][ny] == '@')
dfs(nx, ny);
}//*米 3*3 =9 但是map[x][y]本身被标记了,所以是八个方向
}
return;
}
void solve()
{
res = 0;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
if (map[i][j] == '@') {
dfs(i,j);
res++;
}
}
}
}
int main()
{
//freopen("data.in","r",stdin);
while (cin >> row >> column, row || column)
{
for (int i = 0; i < row; i++)
cin >> map[i];
solve();
cout<<res<<endl;
}
return 0;
}
0 0
- 杭电1241-Oil Deposits
- 杭电1241 Oil Deposits
- 杭电1241Oil Deposits
- 【杭电】[1241]Oil Deposits
- 杭电1241 Oil Deposits
- 杭电 1241 Oil Deposits
- 杭电 hdu 1241 Oil Deposits
- Oil Deposits HDU杭电1241
- 杭电 1241 Oil Deposits 递归 DFS
- 杭电(hdu)1241 Oil Deposits
- hdu 杭电 1241 Oil Deposits
- 【杭电1241】Oil Deposits(DFS)
- 【HUD 杭电 1241】Oil Deposits
- 杭电1241Oil Deposits DFS 搜索
- 杭电ACM-1241 Oil Deposits
- 杭电 1006 Oil Deposits
- HDU--杭电--1241--Oil Deposits--广搜
- 杭电1241--Oil Deposits(BFS)
- php微信支付(仅Jsapi支付)详细步骤.----仅适合第一次做微信开发的程序员
- 商品以省市方式显示百分比数量
- 用pathinfo()+$_FILES获取文件上传时的一些信息
- python hashlib模块
- 如何使用View自定义属性画圆
- 杭电1241 Oil Deposits
- HDU 4280 Island Transport 网络流sap
- A*算法
- ios有关UITableView单选多选框的实现
- 大数乘法
- Android编码规范
- java中关于范型使用的小技巧
- CallBack机制
- 我的Unity 3D之旅——第一人称射击游戏(4)