POJ 1562 Oil Deposits
来源:互联网 发布:淘宝协商历史 编辑:程序博客网 时间:2024/05/16 04:56
Problem: 1562 User: nastaMemory: 764K Time: 16MSLanguage: G++ Result: Accepted题意:
相临的‘@’是一个油田,输出有多少个油田。
简单的搜索题,DFS。
#include <iostream>//#include <fstream>#include <cstring>#define SIZE 100using namespace std;char f[SIZE][SIZE];char vis[SIZE][SIZE];char d[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};int m, n, ans;int dfs(int x, int y){ if(f[x][y] != '@' || vis[x][y] == 1) return 1; vis[x][y] = 1; for(int i=0; i < 8; ++i) { int dx = x + d[i][0]; int dy = y + d[i][1]; dfs(dx, dy); } return 1;}int main(){ //freopen("in.txt", "rb+", stdin); while(cin >> m >> n, m!=0) { ans = 0; memset(f, 0, sizeof(char)*SIZE*SIZE); memset(vis, 0, sizeof(char)*SIZE*SIZE); for(int i=0; i < m; ++i) for(int j=0; j < n; ++j) cin >> f[i][j]; for(int i=0; i < m; ++i) for(int j=0; j < n; ++j) { if(f[i][j] == '@' && vis[i][j] == 0) ans += dfs(i, j); } printf("%d\n", ans); } //fclose(stdin); return 0;}
- Oil Deposits(POJ 1562)
- poj 1562 Oil Deposits
- POJ 1562 Oil Deposits
- poj 1562 Oil Deposits
- poj 1562 Oil Deposits
- poj-1562Oil Deposits
- POJ-1562-Oil Deposits
- POJ 1562 Oil Deposits
- POJ 1562 Oil Deposits
- POJ 1562 Oil Deposits
- POJ 1562 Oil Deposits
- poj 1562 Oil Deposits
- poj 1562 Oil Deposits
- POJ:1562 Oil Deposits
- poj 1562 Oil Deposits
- poj 1562:Oil Deposits
- poj 1562 oil Deposits
- POJ 1562 Oil Deposits
- 超级实用且不花哨的js代码大全
- 让你对Digital Camera完全了解的88条名词解释
- osCache 简单使用
- Android-Adapter
- 关于database product name cannot be null的解决方法
- POJ 1562 Oil Deposits
- Delphi 实现任务栏多窗口图标显示
- 项目问题2
- Python的IDLE工具安装
- do not try to modified the value in const region
- 模板语言NVelocity的注意点(1)
- 《ASP.NET 本质论》HttpApplication的处理管道
- 设计一个表格控件,总在这个过程出错,不知道原因出在哪里,高手帮我找找原因?
- linux内核参数"vga="如何影响显示模式