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. 一个list<Map>里map其中的一个字段的值相同,如何判断这个字段相同,就把这个map的其他字段存入另一个map中

    //不建议使用Map保存这些,使用实体bean更好 package com.rxlamo.zhidao;   import java.util.*;   public class Main {     ...

  2. 5 款最酷的 Linux 终端模拟器

    转载:https://cloud.tencent.com/developer/article/1040344 首先我要推荐的第一个终端是 Xiki. Xiki 是 Craig Muth 的智慧结晶,他 ...

  3. Java中的集合Collection

    集合是什么? Java集合类存放于 java.util 包中,是一个用来存放对象的容器. 注意:①.集合只能存放对象.比如你存一个 int 型数据 1放入集合中,其实它是自动转换成 Integer 类 ...

  4. Docker安装redis3.2

    1.拉取redis3.2镜像 2.使用docker images查看拉去下来的镜像 3.运行容器,命令如下 docker run -p : -v $PWD/data:/data -d redis:3. ...

  5. Oracle 11g win32位 window7下安装教程

    1.首先是去http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html官网下载oracle11 ...

  6. kotlin之注解

    注解是用来代码添加元数据的一种手段,要声明一个 注解,需要在类之前添加annotation修饰符 annotation class demo 注解其他属性,可以通过向注解类添加元注解的方式来指定 @T ...

  7. kotlin之MutableMap委托

    fun main(arg: Array<String>) { val map = mutableMapOf("name" to "tom", ) v ...

  8. flask的post,get请求及获取不同格式的参数

    flask的post,get请求及获取不同格式的参数 1 获取不同格式参数 1.0 获取json参数 Demo from flask import Flask, request, jsonify ap ...

  9. mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)

    1:问题如下: 原因是 新版的MongoDB已经不支持addUser方法了. 改成createUser了. 使用方法如下    2:具体解释一下db.createUser()方法的用法   定义: 创 ...

  10. C++ STL partial_sort_copy

    #include <iostream>#include <deque>#include <algorithm>#include <vector> usi ...