BFS。当水滴破裂飞溅后,直到碰到水滴才会停止(观察case1)。同时,考虑当水滴飞溅到点(x,y)并且该点同一时间破裂的情况,该水滴算作吸收。

 /* 3451 */
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std; #define MAXN 105 typedef struct node_t{
int x,y,d,t;
node_t() {}
node_t(int xx, int yy, int dd, int tt) {
x = xx; y = yy; d = dd; t = tt;
}
} node_t; node_t beg;
int bx, by;
int n, m, l;
int map[MAXN][MAXN];
int t[MAXN][MAXN];
int dir[][] = {
-,,,,,-,,
}; inline bool check(int x, int y) {
return x< || x>=n || y< || y>=m;
} bool isValid() {
int i, j; for (i=; i<n; ++i)
for (j=; j<m; ++j)
if (map[i][j])
return false;
return true;
} void bfs() {
int x, y, d;
int i, j, k;
node_t nd;
queue<node_t> Q; memset(t, , sizeof(t));
if (map[bx][by] == l) {
map[bx][by] = ;
t[bx][by] = ;
nd.t = ;
for (i=; i<; ++i) {
nd.x = bx + dir[i][];
nd.y = by + dir[i][];
if (check(nd.x, nd.y))
continue;
nd.d = i;
Q.push(nd);
}
} else {
++map[bx][by];
return ;
} while (!Q.empty()) {
nd = Q.front();
Q.pop();
if (map[nd.x][nd.y] == l) {
// break
map[nd.x][nd.y] = ;
t[nd.x][nd.y] = nd.t;
for (i=; i<; ++i) {
x = nd.x + dir[i][];
y = nd.y + dir[i][];
if (check(x, y))
continue;
Q.push(node_t(x, y, i, nd.t+));
}
} else if (map[nd.x][nd.y]) {
// absorb
++map[nd.x][nd.y];
} else if (t[nd.x][nd.y] != nd.t) {
// no drop, continue fly
x = nd.x + dir[nd.d][];
y = nd.y + dir[nd.d][];
if (check(x, y))
continue;
Q.push(node_t(x, y, nd.d, nd.t+));
}
}
} int main() {
int t;
int i, j, k;
bool flag; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &t);
while (t--) {
scanf("%d %d %d", &n, &m, &l);
flag = false;
for (i=; i<n; ++i) {
for (j=; j<m; ++j) {
scanf("%d", &map[i][j]);
}
}
flag = isValid();
scanf("%d", &k);
while (k--) {
scanf("%d %d", &bx, &by);
--bx; --by;
if (flag == false) {
bfs();
flag = isValid();
}
}
if (flag) {
puts("YES");
} else {
puts("NO");
for (i=; i<n; ++i) {
for (j=; j<m; ++j)
printf("%d ", map[i][j]);
printf("\n");
}
}
} return ;
}

【HDOJ】3451 Beat drop的更多相关文章

  1. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  2. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  3. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  4. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  5. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  6. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  7. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  8. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

  9. 【HDOJ】【1512】Monkey King

    数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...

随机推荐

  1. mysql使用硬链接配合truncate 删除2.2T的表 --杨奇龙

    http://blog.csdn.net/wyzxg/article/details/8626814 http://blog.itpub.net/22664653/viewspace-750408/ ...

  2. syslog实例详解rsyslog

    http://blog.csdn.net/chenhao112358/article/details/40892239http://www.cnblogs.com/blueswu/p/3564763. ...

  3. Note | Javascript权威指南[第六版] 第1章:Javascript概述

       JavaScript是一门高端的.动态的.弱类型的编程语言,非常适合面向对象和函数式的编程风格.JavaScript的语法源自Java,它的一等函数(first-class function)来 ...

  4. Dapper Use For Net

    Dapper.Net by example januari 6, 2012 When the team behind StackOverflow released the mini-ORM Dappe ...

  5. 配置Nginx 1.8支持PHP 5.6

    启动PHP和Nginx 修改Nginx配置文件/usr/local/nginx/conf/nginx.conf server { listen ; server_name localhost; loc ...

  6. CSS样式权值

    内联样式表(InLine style)>内部样式表(Internal style sheet)>外部样式表(External style sheet) 例外:但如果外部样式表放在内部样式表 ...

  7. .net又一个生成缩略图的方法,不变形,非常好用

    生成缩略图是一个十分常用功能,找到了一个方法,重写部分代码,实用又好用,.net又一个生成缩略图的方法,不变形 /// <summary> /// 为图片生成缩略图 by 何问起 /// ...

  8. java对象与xml相互转换 ---- xstream

    XStream是一个Java对象和XML相互转换的工具,很好很强大.提供了所有的基础类型.数组.集合等类型直接转换的支持. XStream中的核心类就是XStream类,一般来说,熟悉这个类基本就够用 ...

  9. VSS Admin 清除密码

    [参阅链接]http://www.cnblogs.com/Zealot/archive/2004/09/18/44309.html the secret is to hack the um.dat f ...

  10. iPhone中如何判断当前相机是否可用

    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; if (![UIImag ...