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
0
1

题目大意:
给出一个m*n的矩阵 q 个需要敲打的位置,矩阵里面有n*m个方块,由于与机架和其他部件的摩擦,滑块稳定,不会掉落。但是这些障碍物可以被击倒。当一个方块被击倒时,其他剩余的方块也可能掉落,因为其他剩余挡块提供的摩擦力可能不再支撑它们,如果一个区块被敲击或不稳定,它也会掉落。让我们输出每个敲打位置敲打后所掉落的方块个数。

思路:
首先要知道每个方块不能保持稳定的条件分为四种是:

1. 方块下方没有方块: 
        (1).方块左侧没有方块;
        (2).方块右侧没有方块;
  2. 方块上方没有方块:
        (1).方块左侧没有方块;
        (2).方块右侧没有方块;

所以我们只需在每个方块的上下左右做个记号即可;

PS: 我为什么错就是因为把next定义成了数组;不想说了,o(╥﹏╥)o,ε(┬┬﹏┬┬)3 哭了

详细看代码:

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

Block Breaker HDU - 6699(深搜,水,写下涨涨记性)的更多相关文章

  1. HDU 3720 深搜 枚举

    DES:从23个队员中选出4—4—2—1共4种11人来组成比赛队伍.给出每个人对每个职位的能力值.给出m组人在一起时会产生的附加效果.问你整场比赛人员的能力和最高是多少. 用深搜暴力枚举每种类型的人选 ...

  2. hdu 1181 深搜

    中文题 深搜 许久没写鸟,卡在输入问题上... #include <iostream> #include <string> using namespace std; bool ...

  3. hdu 1010 深搜+剪枝

    深度搜索 剪枝 还不是很理解 贴上众神代码 //http://blog.csdn.net/vsooda/article/details/7884772#include<iostream> ...

  4. hdu 1716 深搜dfs

    #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 5 int f[N]; int ...

  5. hdu 1518 深搜

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...

  6. hdu 5648 DZY Loves Math 组合数+深搜(子集法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5648 题意:给定n,m(1<= n,m <= 15,000),求Σgcd(i|j,i&am ...

  7. HDU 4597 Play Game(记忆化搜索,深搜)

    题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...

  8. 深搜基础题目 杭电 HDU 1241

    HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...

  9. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

随机推荐

  1. 数据结构实验之图论八:欧拉回路(SDUT 3364)

    Problem Description 在哥尼斯堡的一个公园里,有七座桥将普雷格尔河中两个岛及岛与河岸连接起来. 能否走过这样的七座桥,并且每桥只走一次?瑞士数学家欧拉最终解决了这个问题并由此创立了拓 ...

  2. (转)初试 Netflix 开源持续云交付平台 Spinnaker

    目录 Spinnaker 介绍 环境.软件准备 安装 Development Spinnaker 配置依赖环境 配置并安装 Spinnaker 演示 Spinnaker Pipeline 演示 Spi ...

  3. navicat连接远程数据库报错'client does not support authentication protocol requested by server consider ...'解决方案

    [1.cmd终端连接远程mysql数据库方法] mysql -uhello -pworld   -h192.168.1.88 -P3306 -Dmysql_oa mysql -u用户名 -p密码 -h ...

  4. RAD,Eclipse切換界面語言(中日英)

    找到RAD的EXE的位置: 右鍵→屬性→Link先(Target) 將原來的"C:\Program Files\IBM\SDP\eclipse.exe" -product com. ...

  5. TNetHttpClient的用法

    TNetHttpClient的用法 TNetHttpClient是DELPHI XE8新增加的控件. 在之前,我们一般都是使用IDHTTP控件,但在安卓.IOS等非WINDOWS平台,IDHTTP访问 ...

  6. Flume-自定义 Source 读取 MySQL 数据

    开源实现:https://github.com/keedio/flume-ng-sql-source 这里记录的是自己手动实现. 测试中要读取的表 CREATE TABLE `student` ( ` ...

  7. SQLW3School-高级:SQL TOP 子句

    ylbtech-SQLW3School-高级:SQL TOP 子句 1.返回顶部 1. TOP 子句 TOP 子句用于规定要返回的记录的数目. 对于拥有数千条记录的大型表来说,TOP 子句是非常有用的 ...

  8. centos7.4出现yum command not found

    购买的云服务器运行yum命令出现yum command not found. 通过将云主机自带的yum和python卸载掉,并且同时需要关注/usr/bin/yum文件的首行解释.我定义其为" ...

  9. Android之view的工作原理2

    学习内容 View的底层工作原理,比如View的测量流程.布局流程以及绘制流程:以及常见的View回调方法:熟悉掌握前面的知识后,自定义View的时候也会更加的得心应手. 4.1 初识ViewRoot ...

  10. Reset Password 重置密码 (CentOS 5,6,7 ; Juniper Networks: SRX100 )

    一些重置root 密码的文档分享(来自官网): CentOS 5,6,7 Juniper Networks :  SRX100 链接:https://share.weiyun.com/5BM4kwK ...