[dfs] HDU 2019 Multi-University Training Contest 10 - Block Breaker
Block Breaker
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
However, the blocks can be knocked down. When a block is knocked down, other remaining blocks may also drop since the friction provided by other remaining blocks may not sustain them anymore. Formally, a block will drop if it is knocked or not stable, which means that at least one of the left block and the right block has been dropped and at least one of the front block and the back block has been dropped. Especially, the frame can be regarded as a huge stable block, which means that if one block's left is the frame, only when its right block has been dropped and at least one of the front block and the back block has been dropped can it drop. The rest situations are similar.
Now you, the block breaker, want to knock down the blocks. Formally, you will do it q times. In each time, you may choose a position (xi,yi). If there remains a block at the chosen position, you will knock it down; otherwise, nothing will happen. Moreover, after knocking down the block, you will wait until no unstable blocks are going to drop and then do the next operation.
For example, please look at the following illustration, the frame is of size 2×2 and the block (1,1) and (1,2) have been dropped. If we are going to knock the block (2,2), not only itself but also the block (2,1) will drop in this knocking operation.
You want to know how many blocks will drop in total in each knocking operation. Specifically, if nothing happens in one operation, the answer should be regarded as 0.
For each test case:
The first line contains three positive integers n,m and q (1≤n,m≤2000,1≤q≤100000), denoting the sizes in two dimensions of the frame and the number of knocking operations.
Each of the following q lines contains two positive integers xi and yi (1≤xi≤n,1≤yi≤m), describing a knocking operation.
2 2 3
1 1
1 2
2 2
4 4 6
1 1
1 2
2 1
2 2
4 4
3 3
1
2
1
1
2
0
1
11
题意:
有n*m个块装在一个框内,以左上角为原点,竖直向下为x正半轴,水平向右为y正半轴建立坐标系,快和块之间和块和框架之间会有摩擦力,一个块如果上下或左右有方块或框架,则他们之间可以被固定住,否则就会落下
有q次操作,每次操作会将(x,y)位置的块敲掉,问每次操作最多能掉下多少方块,如果操作的位置没有方块则输出0
思路:
可以模拟,用dfs或bfs都行,这里选择dfs,从操作位置开始搜索,如果搜索超出了边界或搜到了空位置就返回,否则就把当前位置置为空且答案+1,
从当前位置向周围检查,如果超出边界就跳过(因为我把框架也当成方块,但这个方块必须被固定而不能落下,所以检查到边界时跳过)否则如果检查到的方块不为空且他上下没有对应方块且左右没有对应方块就搜索这个检查到的位置
#include<bits/stdc++.h>
using namespace std;
const int amn=2e3+;
int n,m,q,ans,dx,dy,td[][]={{,},{-,},{,},{,-}};
bool idx[amn][amn];
bool jg(int x,int y){
return idx[x-][y]&&idx[x+][y]||idx[x][y-]&&idx[x][y+]; ///如果上下有对应方块或左右有对应方块则返回1,否则返回0
}
void dfs(int x,int y){
if(!idx[x][y]||x<||x>n||y<||y>m)return ;
idx[x][y]=;
ans++;
// cout<<x<<' '<<y<<endl;
for(int i=;i<;i++){
dx=x+td[i][];
dy=y+td[i][];
if(dx<||dx>n||dy<||dy>m)continue;
if(!jg(dx,dy)&&idx[dx][dy]){
dfs(dx,dy);
}
}
}
int main(){
int T,xi,yi;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n+;i++) ///把边界也处理为方块,不过边界方块是固定的不能掉落
for(int j=;j<=m+;j++)
idx[i][j]=;
while(q--){
scanf("%d%d",&xi,&yi);
ans=;
dfs(xi,yi);
printf("%d\n",ans);
}
}
}
/**
有n*m个块装在一个框内,以左上角为原点,竖直向下为x正半轴,水平向右为y正半轴建立坐标系,快和块之间和块和框架之间会有摩擦力,一个块如果上下或左右有方块或框架,则他们之间可以被固定住,否则就会落下
有q次操作,每次操作会将(x,y)位置的块敲掉,问每次操作最多能掉下多少方块,如果操作的位置没有方块则输出0
可以模拟,用dfs或bfs都行,这里选择dfs,从操作位置开始搜索,如果搜索超出了边界或搜到了空位置就返回,否则就把当前位置置为空且答案+1,
从当前位置向周围检查,如果超出边界就跳过(因为我把框架也当成方块,但这个方块必须被固定而不能落下,所以检查到边界时跳过)否则如果检查到的方块不为空且他上下没有对应方块且左右没有对应方块就搜索这个检查到的位置
**/
[dfs] HDU 2019 Multi-University Training Contest 10 - Block Breaker的更多相关文章
- hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)
CRB and Tree Time Limit: 8000/4000 MS (J ...
- [二分,multiset] 2019 Multi-University Training Contest 10 Welcome Party
Welcome Party Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)T ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 10(9/11)
2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...
- 2016 Multi-University Training Contest 10
solved 7/11 2016 Multi-University Training Contest 10 题解链接 分类讨论 1001 Median(BH) 题意: 有长度为n排好序的序列,给两段子 ...
- 2019 Multi-University Training Contest 10 I Block Breaker
Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m squ ...
- 2019 Multi-University Training Contest 10
目录 Contest Info Solutions C - Valentine's Day D - Play Games with Rounddog E - Welcome Party G - Clo ...
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- 2019DDCTF部分Writeup
-- re Windows Reverse1 通过DIE查壳发现存在upx,在linux上upx -d脱壳即可,拖入IDA,通过关键字符串找到关键函数: main函数中也没有什么,将输入的字符串带到s ...
- react ReactDOMServer
此文章是翻译ReactDOMServer这篇React(版本v15.4.0)官方文档. ReactDOMServer 如果你用script 标签来使用React,这些顶级APIs 将会在全局React ...
- android编译架构之添加C项目
1. 增加一个项目与android编译中枢息息相关.特别需要告诉编译中枢的一些特别信息. 例如: A 这个项目target名字是什么 B 这个项目编译类型是什么,bin?c?lib?or jar? ...
- 天哪!毫无思绪!令人感到恐惧的数学(水题?)(TOWQs)
这道题的题目描述灰常简单,第一眼看以为是一道十分水的题目: 但是!!!(我仔细一看也没有发现这背后隐藏着可怕的真相~) 下面给出题目描述: 给出一个整数x,你可以对x进行两种操作.1.将x变成4x+3 ...
- flume install
flume install flume 安装 123456 [root@10 app][root@10 app]# mv apache-flume-1.7.0-bin /mnt/app/flume[r ...
- JavaScript的封装和继承
提到JavaScript"面向对象编程",主要就是封装和继承,这里主要依据阮一峰及其他博客的系列文章做个总结. 继承机制的设计思想 所有实例对象需要共享的属性和方法,都放在这个对象 ...
- 初学Qt——vs2012开发环境下的窗体跳转
最近接了份外快,要求使用vs+qt开发一个简单的数据管理系统.qt开发使用的语言是c++,然而c++只是大一第二学期有教过而已,基本也差不多忘光了,废话不多说,讲下今天遇到的问题吧 如标题所说,窗体跳 ...
- HTTP协议 有这篇文章足够了
HTTP 协议详解 HTTP(HyperText Transfer Protocol)超文本传输协议.其最初的设计目的是为了提供一种发布和接收HTML页面的方法. HTTP是一个客户端(用户)和服务端 ...
- Particle Filter Algorithm
目录 问题提出 算法研究现状 算法原理 问题提出 在现实科研问题中,其中有很多都是非线性的.要想求得问题的解,就需要非线性的算法.所谓非线性滤波,就是基于带有噪声的观测值,估计非线性系统动态变化的状态 ...
- 一起了解 .Net Foundation 项目 No.10
.Net 基金会中包含有很多优秀的项目,今天就和笔者一起了解一下其中的一些优秀作品吧. 中文介绍 中文介绍内容翻译自英文介绍,主要采用意译.如与原文存在出入,请以原文为准. LLILC LLILC ( ...