**链接 : ** Here!

**思路 : ** 搜索判断连通块个数, 所以 $DFS$ 或则 $BFS$ 都行喽...., 首先记录一下整个地图中所有$Oil$的个数, 然后遍历整个地图, 从油田开始搜索它所能连通多少块其他油田, 只需要把它所连通的油田个数减去, 就ok了


/*************************************************************************
> File Name: E.cpp
> Author:
> Mail:
> Created Time: 2017年11月26日 星期日 10时51分05秒
************************************************************************/ #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; #define MAX_N 150
int n, m;
int total_num;
int vis[MAX_N][MAX_N];
int dx[8] = {0, 0, -1, 1, 1, -1, 1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, -1, 1};
char G[MAX_N][MAX_N]; void dfs(int x, int y) {
vis[x][y] = 1;
for (int i = 0 ; i < 8 ; ++i) {
int now_x = x + dx[i];
int now_y = y + dy[i];
if (vis[now_x][now_y]) continue;
if (now_x < 0 || now_x >= n || now_y < 0 || now_y >= m) continue;
if (G[now_x][now_y] != '@') continue;
vis[now_x][now_y] = 1;
--total_num;
dfs(now_x, now_y);
}
}
void solve() {
for (int i = 0 ; i < n ; ++i) {
for (int j = 0 ; j < m ; ++j) {
if (G[i][j] == '@') {
++total_num;
}
}
}
memset(vis, 0, sizeof(vis));
for (int i = 0 ; i < n ; ++i) {
for (int j = 0 ; j < m ; ++j) {
if (G[i][j] != '@' || vis[i][j]) continue;
dfs(i, j);
}
}
}
int main() {
while (scanf("%d%d", &n, &m) != EOF) {
if (n == 0 && m == 0) break;
memset(G, 0, sizeof(G));
total_num = 0;
for (int i = 0 ; i < n ; ++i) {
getchar();
scanf("%s", G[i]);
}
solve();
printf("%d\n", total_num);
}
return 0;
}

最新文章

  1. iOS Swift 3 open
  2. Android源码-学习随笔
  3. iOS 推送消息长度
  4. OA项目实战(二) 开发准备
  5. Python零散收集:
  6. sql两表联合查询
  7. 类CL_ABAP_TYPEDESCR,动态取得运行时类型
  8. 关于onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
  9. 微信小程序wepy框架开发资源汇总
  10. MySQL skip-character-set-client-handshake导致的一个字符集问题
  11. 【Codeforces 499D】Name That Tune
  12. SpringMVC之接收请求参数和页面传参
  13. shiro中记住我功能
  14. [POC]K8 DLLhijack Test
  15. PetaPoco源代码学习--2.TableInfo、ColumnInfo类和Cache类
  16. DynamicDataDisplay 实时曲线图的使用和沿轴移动的效果
  17. WinForm DataGridView新增加行
  18. html、css如何画实心圆
  19. 1067 Sort with Swap(0, i) (25 分)
  20. [SceneKit] 不会 Unity3D 的另一种选择

热门文章

  1. NS3网络仿真(5): 数据包分析
  2. mongoDB学习笔记——在C#中查询
  3. 怎样动态设置GridView的宽和高(Android)
  4. Git 少用 Pull 多用 Fetch 和 Merge 【已翻译100%】【转】
  5. What is the difference between task and thread?
  6. poj2342 Anniversary party (树形dp)
  7. 【BZOJ 3942】 Censoring
  8. 杂项:Web API
  9. git拉取远端改变,但是不覆盖本地的修改
  10. 【专题系列】单调队列优化DP