【HDOJ】3451 Beat drop
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的更多相关文章
- 【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 ...
随机推荐
- oracle中的层级递归查询操作
oracle中的层级操作非常方便,在使用之后爱不释手,以前要实现该种数据查询操作,需要非常复杂的实现过程.在oracle中通过connect by可以实现前面的目的,通常情况下层级查询基本都能实现递归 ...
- Java Socket 学习笔记
TCP协议的Socket编程 Socket:英文中的意思是插座.两个Java应用程序可以通过一个双向的网络通信连接实现数据交换,这个双向链路的一端称为一个Socket.Java中所有关于网络编程的类都 ...
- jni使用
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 简介 详解 JNI 元素 JNI函数实战 AndroidmkApplicationmk Androidmk Applicat ...
- asp.net 实现对xml文件的 读取,添加,删除,修改
用于修改站内xml文件 已知有一个XML文件(bookstore.xml)如下:<?xml version="1.0" encoding="gb2312" ...
- 动软代码生成器三层用于winform
DBUtility项目中的DbHelperSQL.cs (找自己对应的数据库类型) 修改前20行中的数据库连接字符串获取方式为: //数据库连接字符串(web.config来配置),多数据库可使用Db ...
- Swift 中 Selector 方法的访问权限控制问题
今天用Swift写了个视图,在视图上加个手势,如下所示: panGestureRecognizer = UIPanGestureRecognizer(target: self, action: &qu ...
- 大规模字符串检索-压缩trie树
本文使用压缩trie树实现字符串检索的功能.首先将字符串通过编码转化为二进制串,随后将二进制串插入到trie树中,在插入过程中同时实现压缩的功能. 字符编码采用Huffman,但最终测试发现不采用Hu ...
- POJ 1734.Sightseeing trip (Floyd 最小环)
Floyd 最小环模板题 code /* floyd最小环,记录路径,时间复杂度O(n^3) 不能处理负环 */ #include <iostream> #include <cstr ...
- 【实习记】2014-08-10(上)代码跟踪git的想法+归并排序的debug过程
(冒泡,选择,插入,希尔,快速,归并,堆排)周末加班学习C++,打算用C++写七大经典排序代码.发现3个月前自己写的七大经典排序代码(C Language)突然运行出错. Makefile内容 ...
- python - zipfile
参考:http://www.cnblogs.com/sislcb/archive/2008/11/28/1342822.html zipfile - python处理zip文件的压缩与解压 ZipFi ...