Block Breaker HDU - 6699(深搜,水,写下涨涨记性)
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(深搜,水,写下涨涨记性)的更多相关文章
- HDU 3720 深搜 枚举
DES:从23个队员中选出4—4—2—1共4种11人来组成比赛队伍.给出每个人对每个职位的能力值.给出m组人在一起时会产生的附加效果.问你整场比赛人员的能力和最高是多少. 用深搜暴力枚举每种类型的人选 ...
- hdu 1181 深搜
中文题 深搜 许久没写鸟,卡在输入问题上... #include <iostream> #include <string> using namespace std; bool ...
- hdu 1010 深搜+剪枝
深度搜索 剪枝 还不是很理解 贴上众神代码 //http://blog.csdn.net/vsooda/article/details/7884772#include<iostream> ...
- hdu 1716 深搜dfs
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 5 int f[N]; int ...
- hdu 1518 深搜
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...
- 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 ...
- HDU 4597 Play Game(记忆化搜索,深搜)
题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...
- 深搜基础题目 杭电 HDU 1241
HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
随机推荐
- 集合家族——stack
一.概述 在 Java 中 Stack 类表示后进先出(LIFO)的对象堆栈.栈是一种非常常见的数据结构,它采用典型的先进后出的操作方式完成的 它通过五个操作对类 Vector 进行了扩展 ,允许将向 ...
- java试题复盘——11月25日
上: 11.下列表述错误的是?(D) A.int是基本类型,直接存数值,Integer是对象,用一个引用指向这个对象. B.在子类构造方法中使用super()显示调用父类的构造方法,super()必须 ...
- MySQL基础之二:主从复制
# mysql主从复制逻辑: 1.从库执行start slave 开启主从复制. 2.从库请求连接到主库,并且指定binlog文件以及位置后发出请求. 3.主库收到从库请求后,将信息返回给从库,除了信 ...
- macOS Mojave 10.14 无法安装brew缺少Command Line Tools for Xcode的解决办法
问题描述: 首先我的版本是 Xcode 10.1 如果按照以前的方法安装brew 复制 1 /usr/bin/ruby -e "$(curl -fsSL https://raw.github ...
- CentOS7.4中配置jdk环境
参考:https://www.linuxidc.com/Linux/2016-09/135556.htm 1.下载jdk 首先创建安装包放置位置 mkdir -p /usr/local/java 然后 ...
- MD5介绍
md5介绍 1. md5简介 md5的全称是md5信息摘要算法(英文:MD5 Message-Digest Algorithm ),一种被广泛使用的密码散列函数,可以产生一个128位(16字节,1字节 ...
- 冲刺阶段——Day6
[今日进展] 完成登录代码 userRegister类 import java.awt.*; import java.awt.event.ActionEvent; import java.awt.ev ...
- oracle 常用工具类及函数
j_param json; jl_keys json_list; -- 创建json对象j_param j_param := json(p_in_str); -- 校验param域是否缺少必填参数 j ...
- java 测试框架
项目开发过程中使用的单元测试框架有Junit.TestNG以及Mockito,Junit和TestNG使用的比较多,Mockito最近才开始使用. TestNG与JUnit的相同点 1. 使用anno ...
- [转]用代码访问 Https
可以参考: https://blog.csdn.net/irokay/article/details/78801307 跳过证书验证方法 HttpClient简介HTTP 协议可能是现在 Intern ...