【HDOJ】1547 Bubble Shooter
两次BFS,一次扫描关联点。一次扫描可能掉落的情况(即再次扫描所有非爆炸的联通点)。余下未被扫描的点均爆炸。
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- #define MAXN 105
- char map[MAXN][MAXN];
- bool visit[MAXN][MAXN];
- int h, w, x, y;
- int dir[][] = {-,, ,, -,, ,, ,, ,-, -,-, ,-};
- typedef struct node_t {
- int x, y;
- node_t() {}
- node_t(int xx, int yy) {
- x = xx; y = yy;
- }
- } node_t;
- bool check(int x, int y) {
- int ww = w;
- if ((x&) == )
- ww = w-;
- if (x< || x>h || y< || y>ww || visit[x][y])
- return true;
- return false;
- }
- void bfs_Oth(int x, int y) {
- int i, j, nx, ny;
- queue<node_t> Q;
- visit[x][y] = true;
- Q.push(node_t(x,y));
- while (!Q.empty()) {
- node_t nd = Q.front();
- Q.pop();
- j = (nd.x & )<<;
- for (i=j; i<j+; ++i) {
- nx = nd.x + dir[i][];
- ny = nd.y + dir[i][];
- if (check(nx, ny) || map[nx][ny]=='E')
- continue;
- Q.push(node_t(nx, ny));
- visit[nx][ny] = true;
- }
- }
- }
- void bfs() {
- int ans = ;
- int i, j, nx, ny;
- char c = map[x][y];
- queue<node_t> Q;
- memset(visit, false, sizeof(visit));
- visit[x][y] = true;
- Q.push(node_t(x,y));
- while (!Q.empty()) {
- node_t nd = Q.front();
- Q.pop();
- ++ans;
- j = (nd.x & )<<;
- for (i=j; i<j+; ++i) {
- nx = nd.x + dir[i][];
- ny = nd.y + dir[i][];
- if (check(nx, ny) || map[nx][ny]!=c)
- continue;
- Q.push(node_t(nx, ny));
- visit[nx][ny] = true;
- }
- }
- if (ans < ) {
- printf("0\n");
- return ;
- }
- // search the other bubbles
- for (j=; map[][j]; ++j) {
- if (!visit[][j] && map[][j]!='E') {
- bfs_Oth(, j);
- }
- }
- for (i=; i<=h; ++i) {
- for (j=; map[i][j]; ++j) {
- if (!visit[i][j] && map[i][j]!='E')
- ++ans;
- }
- }
- printf("%d\n", ans);
- }
- int main() {
- int i, j;
- #ifndef ONLINE_JUDGE
- FILE *fin = freopen("data.in", "r", stdin);
- #endif
- while (scanf("%d%d%d%d", &h,&w,&x,&y)!=EOF) {
- for (i=; i<=h; ++i) {
- scanf("%s", map[i]+);
- }
- bfs();
- #ifndef ONLINE_JUDGE
- fflush(stdout);
- #endif
- }
- return ;
- }
【HDOJ】1547 Bubble Shooter的更多相关文章
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
- 【HDOJ】【1512】Monkey King
数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...
随机推荐
- Haskell 差点儿无痛苦上手指南
趁着自己重装Linux 虚拟机的机会,把安装 haskell 的过程记录一下,顺便帮那些还犹豫徘徊在haskell门外的读者入门. 基本概念: Haskell : 是一门通用函数式语言,差点儿能够进行 ...
- 合肥三洋股份,惠而浦家电携四大品牌-Take ,所有的市场
大家都知道,数家电企业的日子并不好过.一方面,产品同质化竞争越发激烈.家电市场已进入了恶性价格战时代.还有一方面,消费者对家电产品的需求越发多元化.个性化.这意味着无法满足消费者需求的产品非常 ...
- Python学习之四【变量】
变量:用于引用(绑定)对象的标识符 语法: >>变量名=对象 (数值,表达式等) 如计算圆的面积 PI=3.14 redius:12.3 area=PI*radius**2(**在pyth ...
- JBoss EAP6/AS7/WildFly: How to Use Properties Files Outside Your Archive--reference
Introduction I’d like to preface this post with, really, all properties files should be inside your ...
- linux服务器上的php代码通过nginx发布,解决pathinfo模式问题
附件1为修改前的正常访问php配置文件 附件2为修改后的能通过url地址访问php项目的配置文件 具体操作网址 如下:www.itokit.com/2012/0308/73275.ht ...
- Log4j使用教程 (转载http://www.codeceo.com/article/log4j-usage.html)
日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供方便的日志记录.在apache网站:jakarta.apache.org/log4j 可以免费下载到Log ...
- 《Android开发艺术探索》读书笔记 (2) 第2章 IPC机制
2.1 Android IPC简介 (1)任何一个操作系统都需要有相应的IPC机制,Linux上可以通过命名通道.共享内存.信号量等来进行进程间通信.Android系统不仅可以使用了Binder机制来 ...
- 移动页面缩放方法之(二)控制HTML
<!DOCTYPE HTML> <html lang="zh-cn"> <head> <meta http-equiv="Con ...
- ASP.NET 多线程 监控任务执行情况,并显示进度条
关于多线程的基本概念和知识在本文中不多讲,而且我懂的也不是很透,说的太多误人子弟...对于我来说,做本文提到的功能够用就行,等实现其他效果不够用的时候,再深入研究 推荐看园子里的两篇博客应该就有个基本 ...
- HTML5 Blob与ArrayBuffer、TypeArray和字符串String之间转换
1.将String字符串转换成Blob对象 //将字符串 转换成 Blob 对象 var blob = new Blob(["Hello World!"], { type: 'te ...