题目传送门

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

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

#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. 前端性能优化(DOM篇)

    原文链接:https://segmentfault.com/a/1190000000490322 缓存DOM对象 JavaScript的DOM操作可以说是JavaScript最重要的功能,我们经常要根 ...

  2. 4.3 map和multimap

    使用map multimap必须包含头文件map *:multimap 1)multimap定义 template<class Key,class Pred=less<Key>,cl ...

  3. 浅谈我的编程之路——感谢引领我的leader

    在开发的道路上,就始终无法避开版本控制,哪怕你是独自一人进行开发,版本控制也是有必要的,从最早开始使用CVS,到后来使用SVN,再到git,最后又回到了SVN,但是不知道为什么真的对SVN很无爱. 现 ...

  4. bootstratp图标的使用

    bootstratp作为一个优秀的前端框架,最近使用了其中的Glyphicon Halflings的字体图标.起初一直显示不出来,后面通过搜索相关资料直到成功显示,在此做一些总结,方便后面复习. 1. ...

  5. MVC – 5.MVC设计模式和.NetMVC框架

    MVC模式-设计模式 •控制器(Controller)- 负责转发请求,对请求进行处理. •视图 (View) - 界面设计人员进行图形界面设计. •模型 (Model)-业务逻辑.数据.验证规则.数 ...

  6. weblogic监控

    http://wenku.baidu.com/link?url=tQPQ-dgm7NOkEGj_vemwtsPd6TJ6W3x6_0UBLgw61N982SwPlz-QFxqncsmPGqHwJAEF ...

  7. 【转载】 Python 调整屏幕分辨率

    转载来自: http://www.cnblogs.com/fatterbetter/p/4115423.html 需要用windows的api,ChangeDisplaySettings 实现代码如下 ...

  8. 团队作业-第一周-NABCD竞争性需求分析

      1.  Need 需求 随着科技信息的发展,传统的课堂点名亟待步入信息处理的轨道,移动校园课堂点名软件恰好的切入了这个需求点,市场中词类软件也为数不多,因此需求也是比较强烈. 2. Approac ...

  9. Beego框架使用

    go get github.com/astaxie/beego vim hello.go package main import "github.com/astaxie/beego" ...

  10. windows phone SDK 8.0 模拟器异常 0x89721800解决办法

    删除 APPDATA\LOCAL\Microsoft\Phone Tools\CoreCon\10.0 从新启动即可!