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

非常基础深度搜题,有点生。直接写的,死活都是WA,过了过了这个题。

#include<iostream>
#include<cstdio>
using namespace std;
#define maxx 2010
int n,m;
int net[4][2]={0,1,1,0,-1,0,0,-1};//这里千万不要用next[];
struct node{
int s;//记录此位置是否还有方块
int q,d,l,r;//记录方块的上下左右是否还有方块
}a[maxx][maxx];
int dfs(int x,int y){ //进行深搜看是否还有满足掉落的方块
int sum=0;
for(int i=0;i<4;i++){
int tx=x+net[i][0];
int ty=y+net[i][1];
if(tx<=0||ty<=0||tx>n||ty>m||!a[tx][ty].s)
continue;
if((!a[tx][ty].q||!a[tx][ty].d)&&(!a[tx][ty].l||!a[tx][ty].r)){//不稳定方块的判断条件,上面有介绍;
sum++;
a[tx][ty].s=0;
a[tx+1][ty].l=0;
a[tx-1][ty].r=0;
a[tx][ty+1].d=0;
a[tx][ty-1].q=0;
sum+=dfs(tx,ty);
}
}
return sum;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int q;
scanf("%d%d%d",&n,&m,&q);
for(int i=0;i<=n+1;i++)//为啥从“0”到“n+1”和“0”到“m+1”
for(int j=0;j<=m+1;j++){//因为矩阵的四条边都是有摩擦的
a[i][j].s=1,a[i][j].d=1,a[i][j].l=1;
a[i][j].r=1,a[i][j].q=1;
}
int x,y;
for(int i=1;i<=q;i++){
int sum=0;//记录掉的个数
scanf("%d%d",&x,&y);
if(a[x][y].s){
sum++;
//把与此位置有关联的方块所对应的位置标记为“0”
a[x][y-1].q=0;//“下”方块的上标记为0;
a[x+1][y].l=0;//同理右面的左标记为0;
a[x-1][y].r=0;//左的右为0
a[x][y+1].d=0;//上的下为0;
a[x][y].s=0;//掉落将其标记为0
sum+=dfs(x,y);
}
printf("%d\n",sum);
}
}
return 0;
}

2019 Multi-University Training Contest 10 I Block Breaker的更多相关文章

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

  2. 2016 Multi-University Training Contest 10

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

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

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

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

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

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

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

  7. [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)T ...

  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. 【2019 Multi-University Training Contest 10】

    01: 02: 03:https://www.cnblogs.com/myx12345/p/11671692.html 04: 05:https://www.cnblogs.com/myx12345/ ...

随机推荐

  1. Loop Unrolling 循环展开

    在csapp第五章5.2中提到了循环展开(loop unrolling).这里展开一下为什么循环展开可以提升程序的效率. 以书中计算数组和的两段代码为例: 1.未展开: void psum1(floa ...

  2. 路由与交换,cisco路由器配置,浮动静态路由

    设置浮动静态路由的目的就是为了防止因为一条线路故障而引起网络故障.言外之意就是说浮动静态路由实际上是主干路由的备份.例如下图: 假如我们设路由器之间的串口(seria)为浮动静态路由(管理距离为100 ...

  3. JAVA debug 调试demo

    1.设置断点,在代码的行号后面鼠标左键即可2.想要看调用方法的执行流程,那么调用方法也要加断点. package day6_debug; /* * 1.设置断点,在代码的行号后面鼠标左键即可 * 2. ...

  4. 听说你想要部署 Octopress?满足你

    Octopress 是一个面向开发者的博客系统,广受程序员的喜爱.既然大家有需求,那么 Octopress 也要安排上~ 云开发(CloudBase)是一款云端一体化的产品方案 ,采用 serverl ...

  5. 好消息,vue3.0 进入 beta 阶段!

    昨天,4 月 16 日,vue 3 正式进入 beta 阶段.同日,尤大参加了 State of Vue 的线上活动,以下是他上传到 google docs 上的 slides : State of ...

  6. 004-流程控制-C语言笔记

    004-流程控制-C语言笔记 学习目标 1.[掌握]关系运算符和关系表达式 2.[掌握]逻辑运算符和逻辑表达式 3.[掌握]运算符的优先级和结合性 4.[掌握]if-else if-else结构的使用 ...

  7. Python导出数据到Excel表格-NotImplementedError: formatting_info=True not yet implemented

    在使用Python写入数据到Excel表格中时出现报错信息记录:“NotImplementedError: formatting_info=True not yet implemented” 报错分析 ...

  8. java面试题(一年工作经验)的心得

    看面试题 正常人第一步肯定都会看面试题,我也不例外,在看的过程中,我发现有些文章写的不错,对我帮助不小值得推荐,如下: Java面试题全集(上) 很多基础的东西,建议先看. 各大公司Java后端开发面 ...

  9. PHP--关于上传文件大小的问题

    参考:https://www.cnblogs.com/jianqingwang/p/5863960.html https://blog.csdn.net/u013168253/article/deta ...

  10. 《Metasploit魔鬼训练营》第一章实践作业

    <Metasploit魔鬼训练营>第一章实践作业 1.搜集Samba服务usermap_script安全漏洞的相关信息,画出该安全漏洞的生命周期图,标注各个重要事件点的日期,并提供详细描述 ...