题目传送门

题意:从炮台射出一个球,三个及以上颜色相同的会掉落,问最后会掉落多少个球

分析:先从炮台找一个连通块,然后与顶部连接的连通块都不会掉落,剩下的就是炮台射出后跟随掉落的。

#include <bits/stdc++.h>

const int N = 100 + 5;
char str[N][N];
int H, W, h, w;
int ans; bool check(int x, int y) {
if (x < 1 || x > H || y < 1 || y > W || (x%2==0 && y==W) || str[x][y] == '@') return false;
return true;
} void DFS(int x, int y, char color, int &cnt) {
if (!check (x, y)) {
return ;
}
if (color != '@' && color != str[x][y]) {
return ;
}
cnt++;
str[x][y] = '@';
DFS (x - 1, y, color, cnt);
DFS (x + 1, y, color, cnt);
DFS (x, y - 1, color, cnt);
DFS (x, y + 1, color, cnt);
if (x & 1) {
DFS (x - 1, y - 1, color, cnt);
DFS (x + 1, y - 1, color, cnt);
} else {
DFS (x - 1, y + 1, color, cnt);
DFS (x + 1, y + 1, color, cnt);
}
} int main() {
while (scanf ("%d%d%d%d", &H, &W, &h, &w) == 4) {
for (int i=1; i<=H; ++i) {
scanf ("%s", str[i] + 1);
for (int j=1; j<=W; ++j) {
if (str[i][j] == 'E') {
str[i][j] = '@';
}
}
}
int cnt = 0;
DFS (h, w, str[h][w], cnt);
int ans = cnt;
if (ans < 3) {
puts ("0");
continue;
}
for (int i=1; i<=W; ++i) {
DFS (1, i, '@', cnt);
}
for (int i=1; i<=H; ++i) {
for (int j=1; j<=W; ++j) {
if (i % 2 == 0 && j == W) continue;
if (str[i][j] != '@') {
ans++;
}
}
}
printf ("%d\n", ans);
} return 0;
}

  

DFS(连通块) ZOJ 2743 Bubble Shooter的更多相关文章

  1. ZOJ 3781 - Paint the Grid Reloaded - [DFS连通块缩点建图+BFS求深度][第11届浙江省赛F题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Time Limit: 2 Seconds      Me ...

  2. ZOJ 3781 Paint the Grid Reloaded(DFS连通块缩点+BFS求最短路)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5268 题目大意:字符一样并且相邻的即为连通.每次可翻转一个连通块X( ...

  3. Codeforces Round #375 (Div. 2)——D. Lakes in Berland(DFS连通块)

    D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. P1141 01迷宫 dfs连通块

    题目描述 有一个仅由数字000与111组成的n×nn \times nn×n格迷宫.若你位于一格0上,那么你可以移动到相邻444格中的某一格111上,同样若你位于一格1上,那么你可以移动到相邻444格 ...

  5. DFS(连通块) HDU 1241 Oil Deposits

    题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...

  6. HDU1241 Oil Deposits(dfs+连通块问题)

    背景描述 ztw同志负责探测地下石油储藏.ztw现在在一块矩形区域探测石油.他通过专业设备,来分析每个小块中是否蕴藏石油.如果这些蕴藏石油的小方格相邻(横向相邻,纵向相邻,还有对角相邻),那么它们被认 ...

  7. Artwork (Gym - 102346A)【DFS、连通块】

    Artwork (Gym - 102346A) 题目链接 算法 DFS,连通块 时间复杂度:O(k*n + k * k) 1.这道题就是让你判断从(0,0)到(m,n),避开中途所有的传感器(传感器的 ...

  8. ZOJ 1709 Oil Deposits(dfs,连通块个数)

    Oil Deposits Time Limit: 2 Seconds      Memory Limit: 65536 KB The GeoSurvComp geologic survey compa ...

  9. DFS序+线段树 hihoCoder 1381 Little Y's Tree(树的连通块的直径和)

    题目链接 #1381 : Little Y's Tree 时间限制:24000ms 单点时限:4000ms 内存限制:512MB 描述 小Y有一棵n个节点的树,每条边都有正的边权. 小J有q个询问,每 ...

随机推荐

  1. sqlserver 解析Json字符串

    转自:https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/ http://ww ...

  2. vs c# int & int32

    在vs c#中,int就等价于int32, 所以通常也是使用int32 当在统计总数时,最好使用int32,int16数值范围太小,如果超出,就会变成随机数.

  3. vector的erase的用法

    vector<string>::iterator it = v.erase(v.begin() + 3, v.begin() + 6); 可以直接从begin进行加减,比如我们要移除第3个 ...

  4. qt_计算器的简单实现

    //阶乘不知道怎么实现不了/(ㄒoㄒ)/~~,以后慢慢调试吧......... //转换为后缀表达式,实现最主要功能 void MainWindow::toPostfix () { QString e ...

  5. SQLServer之数据类型

    1.整数数据类型整数数据类型是常用的数据类型之一,主要用于存储数值,可以直接进行数据运算而不必使用函数转换.(1).bigint 每个bigint存储在8个字节中,其中一个二进制位表示符号位,其它63 ...

  6. pyinstaller打包pyqt文件

    打包pyqt文件 如何将pyqt生成exe的二进制文件呢,pyinstaller就是这样的工具 可以将脚本文件.py 文件转换为编辑后的二进制文件,在进行发布 下面说下,如果打包 一. 安装: 下载地 ...

  7. 【翻译七】java-同步

    Synchronization Threads communicate primarily by sharing access to fields and the objects reference ...

  8. 一致性hash算法简介与代码实现

    一.简介: 一致性hash算法提出了在动态变化的Cache环境中,判定哈希算法好坏的四个定义: 1.平衡性(Balance) 2.单调性(Monotonicity) 3.分散性(Spread) 4.负 ...

  9. 手机访问 localhost

    为了测试开发的手机网站,常常需要使手机直接访问本地网络.在这个过程中碰到几个问题,记下来供以后参考 1. 在本地主机运行apache后,使用localhost和127.0.0.1可以访问页面,但使用I ...

  10. PHPCMS 多站点管理切换问题

    打开系统函数库global.func.php 可以看到获取站点ID的函数如下 /** * 获取当前的站点ID */ function get_siteid() { static $siteid; if ...