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

递归求解,不过注意一定要使用scanf,printf;如果使用cin,cout一定会超时的,刚开始我就是这样显示超时。
AC代码:

include

include

using namespace std;
int a[2005][2005],n,m,q,s;
int d[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
int panduan(int x,int y){
if((a[x-1][y]==-1||a[x+1][y]==-1)&&(a[x][y+1]==-1||a[x][y-1]==-1)) return 1;
else return 0;
}
void digui(int x,int y){
for(int i=0;i<4;i++){
if(x+d[i][0]>=1&&x+d[i][0]<=n&&y+d[i][1]>=1&&y+d[i][1]<=m&&a[x+d[i][0]][y+d[i][1]]!=-1&&panduan(x+d[i][0],y+d[i][1])){
a[x+d[i][0]][y+d[i][1]]=-1,s++,digui(x+d[i][0],y+d[i][1]);
}
}
return ;
}
int main(){
int t;scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&q);
memset(a,0,sizeof(a));
while(q--){
s=0;
int x,y;
scanf("%d%d",&x,&y);
if(a[x][y]!=-1){
a[x][y]=-1;
s++;
digui(x,y);
}
printf("%d\n",s);
}
}
return 0;
}

hdu6699Block Breaker的更多相关文章

  1. Circuit Breaker Pattern(断路器模式)

    Handle faults that may take a variable amount of time to rectify when connecting to a remote service ...

  2. customized English word breaker for sql server 2008

    Open the Registry Editor, by: Clicking Start, and clicking Run. In the Run dialog box, in the Open b ...

  3. Circuit Breaker Features

    Better to use a circuit breaker which supports the following set of features: Automatically time-out ...

  4. 谈谈Circuit Breaker在.NET Core中的简单应用

    前言 由于微服务的盛行,不少公司都将原来细粒度比较大的服务拆分成多个小的服务,让每个小服务做好自己的事即可. 经过拆分之后,就避免不了服务之间的相互调用问题!如果调用没有处理好,就有可能造成整个系统的 ...

  5. 断路器(Curcuit Breaker)模式

    在分布式环境下,特别是微服务结构的分布式系统中, 一个软件系统调用另外一个远程系统是非常普遍的.这种远程调用的被调用方可能是另外一个进程,或者是跨网路的另外一台主机, 这种远程的调用和进程的内部调用最 ...

  6. Circuit Breaker模式

    Circuit Breaker模式会处理一些需要一定时间来重连远程服务和远端资源的错误.该模式可以提高一个应用的稳定性和弹性. 问题 在类似于云的分布式环境中,当一个应用需要执行一些访问远程资源或者是 ...

  7. [AOP] 7. 一些自定义的Aspect - Circuit Breaker

    Circuit Breaker(断路器)模式 关于断路器模式是在微服务架构/远程调用环境下经常被使用到的一个模式.它的作用一言以蔽之就是提高系统的可用性,在出现的问题通过服务降级的手段来保证系统的整体 ...

  8. Akka之Circuit Breaker

    这周在项目中遇到了一个错误,就是Circuit Breaker time out.以前没有接触过,因此学习了下akka的断路器. 一.为什么使用Circuit Breaker 断路器是为了防止分布式系 ...

  9. .NET Core中Circuit Breaker

    谈谈Circuit Breaker在.NET Core中的简单应用 前言 由于微服务的盛行,不少公司都将原来细粒度比较大的服务拆分成多个小的服务,让每个小服务做好自己的事即可. 经过拆分之后,就避免不 ...

随机推荐

  1. 2019牛客暑期多校训练营(第三场) - J - LRU management - 模拟

    https://ac.nowcoder.com/acm/contest/883/J 根据这个数据结构的特点,也就是计算机组成原理里面学过的cache的LRU管理算法,每次访问都会在cache中查询一页 ...

  2. 在Linux上下载和安装AAC音频编码器FAAC

    Linux上FAAC的安装 安装 下载 http://downloads.sourceforge.net/faac/faac-1.28.tar.gz 解压 tar zxvf faac-1.28.tar ...

  3. java 回调的原理与实现

    回调函数,顾名思义,用于回调的函数.回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数.回调函数是一个工作流的一部分,由工作流来决定函数的调用(回调)时机. 回调原本应该是一个非常简 ...

  4. MongoDB的使用学习之(二)简介

    原文链接:http://www.cnblogs.com/yxlblogs/p/3681089.html MongoDB 是一个高性能,开源,无模式的文档型数据库,是当前 NoSQL 数据库产品中最热门 ...

  5. Solr的学习使用之(六)获取数据列表-SolrDocumentList

    以下是我项目中获取新闻数据列表的写法,包括数据总量.数据列表,接下来会贴出分片查询(facet)等高级查询 基本的注释都有了: private ListPage<News> queryFr ...

  6. Solr的学习使用之(五)添加索引数据

    1.创建SolrServer类 SolrServer类:提供与Solr实例的连接与通信. 往Solr里添加索引数据,据说有好几种办法,这边利用SolrJ操作solr API完成index操作,具体So ...

  7. docker可视化集中管理工具shipyard安装部署

    docker可视化集中管理工具shipyard安装部署 Shipyard是在Docker Swarm实现对容器.镜像.docker集群.仓库.节点进行管理的web系统. 1.Shipyard功能 Sh ...

  8. 如何同步发送put或者delete请求

    1.必须把前端发送方式改为post . 2.在web.xml中配置一个filter:HiddenHttpMethodFilter过滤器 3.必须携带一个键值对,key=_method,  value= ...

  9. FMC141-4路 250Msps/16bits ADC, FMC板卡

    FMC141-4路 250Msps/16bits ADC, FMC板卡 一.产品概述: 本板卡基于 FMC 标准板卡,实现 4 路 16-bit/250Msps ADC 功能.遵循 VITA 57 标 ...

  10. [Tvvj1391]走廊泼水节(最小生成树)

    [Tvvj1391]走廊泼水节 Description 给定一棵N个节点的树,要求增加若干条边,把这棵树扩充为完全图,并满足图的唯一最小生成树仍然是这棵树.求增加的边的权值总和最小是多少. 完全图:完 ...