Block Breaker

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m square blocks of size 1×1. Due to the friction with the frame and each other, the blocks are stable and will not drop.

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.

 
Input
The first line contains one positive integer T (1≤T≤10), denoting the number of test cases.

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.

 
Output
For each test case, output q lines, each of which contains a non-negative integer, denoting the number of dropped blocks in the corresponding knocking operation.
 
Sample Input
2
2 2 3
1 1
1 2
2 2
4 4 6
1 1
1 2
2 1
2 2
4 4
3 3
 
Sample Output
1
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的更多相关文章

  1. hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)

    CRB and Tree                                                             Time Limit: 8000/4000 MS (J ...

  2. [二分,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 ...

  3. 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 ...

  4. 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 ...

  5. 2015 Multi-University Training Contest 10(9/11)

    2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...

  6. 2016 Multi-University Training Contest 10

    solved 7/11 2016 Multi-University Training Contest 10 题解链接 分类讨论 1001 Median(BH) 题意: 有长度为n排好序的序列,给两段子 ...

  7. 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 ...

  8. 2019 Multi-University Training Contest 10

    目录 Contest Info Solutions C - Valentine's Day D - Play Games with Rounddog E - Welcome Party G - Clo ...

  9. 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) ...

随机推荐

  1. 微软推出中文学习AI助手Microsoft Learn Chinese

    ​ 编者按:美国总统特朗普访华期间,他6岁的外孙女阿拉贝拉用中文普通话演唱和背诵传统诗歌的视频在中国社交媒体上引起广泛关注,可以感受得到,越来越多的人对中文学习充满了兴趣.智能私教微软小英帮助很多中国 ...

  2. 如何应对HR小姐姐的千年历史遗留问题:你为什么从上家公司离职?

    最近找我询问面试问题的学生比较多,而且问的问题基本上都是课堂上讲过的,好吧,在此心疼自己三秒钟. 那么今天就为各位宝宝们整理一下,如何优雅的回复HR小姐姐的这个千年历史遗留问题:你为什么从上家公司离职 ...

  3. DJI大疆创新招聘-自动化测试工程师

    工作地点:深圳 简历发送:sue.li@dji.com 工作职责: 1. 参与自动化测试的设计和开发,参与需求分析和评审,评估合理性和完备性: 任职资格: 1. 本科及以上学历,计算机或软件工程相关专 ...

  4. 阿里大数据竞赛season1 总结

    关于样本测试集和训练集数量上,一般是选择训练集数量不小于测试集,也就是说训练集选取6k可能还不够,大家可以多尝试得到更好的效果: 2. 有人提出归一化方面可能有问题,大家可以查查其他的归一化方法,但是 ...

  5. 5G时代,什么将会消失?

    ​​5G时代说着说着就来了,当然,它不可能一撮而就,但正如4G.移动互联网和WIFI这些东西基本上是日益精进的水平,现如今饭馆的生意是否火爆,不仅仅在于其菜品和服务的质量,更在于他们有没有WIFI以及 ...

  6. CSS的五种定位方式

    CSS中一共有五种定位: position:static:默认值 position:absolute:绝对定位 position:relative:相对对定位 position:fixed:固定定位 ...

  7. Java 集合、数组排序

    在平时开发的过程中,经常会遇到需要对数组.集合中元素按规则进行排序,本文记录在开发过程中可能遇到的情况以及相关的完整代码示例. 知识点 Comparable<T>接口 实现了该接口的对象, ...

  8. 用ABAP 生成二维码 QR Code

    除了使用我的这篇blogStep by step to create QRCode in ABAP Webdynpro提到的使用ABAP webdynpro生成二维码之外,也可以通过使用二维码在线生成 ...

  9. Yuchuan_linux_C 编程之八 文件操作相关函数

    一.整体大纲 st_mode整体介绍: st_mode详细介绍: 二. Linux文件操作相关函数 1. stat 作用:获得文件信息,也可以获取文件大小. 头文件 #include <sys/ ...

  10. day05基本运算符,格式化输出,垃圾回收机制

    内容大纲:1.垃圾回收机制详解(了解) 引用计数 标记清除 分代回收 2.与用户交互 接收用户输入 # python3中 input # python2.7(了解) input raw_input 格 ...