hdu-6699 Block Breaker
题意:
就是给你一个n行m列的矩形,后面将会有q次操作,每次操作会输入x,y表示要击碎第x行第y列的石块,当击碎它之后还去判断一下周围石块是否牢固
如果一个石块的左右两边至少一个已经被击碎且上下也至少一个被击碎,那么这个石块就是不牢固的,可以把这个石块也击碎
对于每一对x,y;要输出一个整数表示此次操作击碎石块多少个
题解:
对于每输入的一对x,y;先判断这个点的石块还在不在了,不在就输出0,在的话标记一下,在以此处为起点开始bfs搜索,搜索过程中经过的点也要标记
再按照石块是否牢固的判断方法对搜索过程中的石块进行判断
代码:
1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<vector>
6 #include<queue>
7 using namespace std;
8 const int INF=0x3f3f3f3f;
9 const int maxn=2505;
10 typedef long long ll;
11 struct shudui
12 {
13 int x,y;
14 } str1,str2;
15 int p[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
16 int n,m,w[maxn][maxn],xx[maxn],yy[maxn];
17 queue<shudui>r;
18 bool panduan(int y,int x)
19 {
20 int flag=0;
21 if(yy[y])
22 {
23 if(xx[x])
24 return 0;
25 else return 1;
26 }
27 else return 1;
28 }
29 int bfs(int ans)
30 {
31 while(!r.empty())
32 {
33 str1=r.front();
34 r.pop();
35 for(int i=0; i<4; ++i)
36 {
37 int x=str2.x=str1.x+p[i][0];
38 int y=str2.y=str1.y+p[i][1];
39 if(x<1 || y<1 || x>m || y>n || w[y][x])
40 {
41 continue;
42 }
43 if((w[y-1][x] || w[y+1][x]) && (w[y][x+1] || w[y][x-1]))
44 {
45 ans++;
46 w[y][x]=1;
47 r.push(str2);
48 }
49 }
50 }
51 return ans;
52 }
53 int v[maxn];
54 int main()
55 {
56 int t;
57 scanf("%d",&t);
58 while(t--)
59 {
60 int q;
61 memset(yy,0,sizeof(yy));
62 memset(xx,0,sizeof(xx));
63 memset(w,0,sizeof(w));
64 while(!r.empty()) r.pop();
65 scanf("%d%d%d",&n,&m,&q);
66 for(int j=1; j<=q; ++j)
67 {
68 int x,y;
69 scanf("%d%d",&y,&x);
70 int ans=0;
71 if(!w[y][x])
72 {
73 str2.x=x;
74 str2.y=y;
75 r.push(str2);
76 w[y][x]=1;
77 ans=bfs(1);
78 }
79 printf("%d\n",ans);
80 }
81 }
82 return 0;
83 }
hdu-6699 Block Breaker的更多相关文章
- Block Breaker HDU - 6699(深搜,水,写下涨涨记性)
Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m squ ...
- [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 ...
- 2019 Multi-University Training Contest 10 I Block Breaker
Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m squ ...
- hdu多校第十场 1009 (hdu6699) Block Breaker bfs/模拟
题意: 紧密排列的方块因为摩擦力一个一个稳定地挤在一起,但当一个方块的四个邻居中,上下两个至少空缺一个,左右两个至少空缺一个,则这个方块也将掉落. 每次锤掉一个方块,求多少个方块受牵连落下. 题解: ...
- 【HDOJ6699】Block Breaker(模拟)
题意:给定一个n*m的网格块,如果一个块水平或垂直方向没有相邻支撑就会掉下去 有q次询问,每次会掉下去一块,问连锁反应新掉下的块数 n,m<=2e3,q<=1e5 思路: #include ...
- hdu6699Block Breaker
Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m squ ...
- 2019DX#10
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Minimum Spanning Trees 22.22%(2/9) 1002 Lin ...
- 2019 Multi-University Training Contest 10
目录 Contest Info Solutions C - Valentine's Day D - Play Games with Rounddog E - Welcome Party G - Clo ...
- Python游戏编程入门 中文pdf扫描版|网盘下载内附地址提取码|
Python是一种解释型.面向对象.动态数据类型的程序设计语言,在游戏开发领域,Python也得到越来越广泛的应用,并由此受到重视. 本书教授用Python开发精彩游戏所需的[]为重要的该你那.本书不 ...
随机推荐
- LeetCode 二分查找模板 II
模板 #2: int binarySearch(vector<int>& nums, int target){ if(nums.size() == 0) return -1; in ...
- Flutter 应用入门:计数器
用Android Studio创建的Flutter应用模板默认是一个简单的计数器示例. // 导入包 import 'package:flutter/material.dart'; // 应用入口,启 ...
- SpringBoot对静态资源的映射规则
在WebMvcAutoConfiguration类中有相对应的方法addResourceHandlers public void addResourceHandlers(ResourceHandler ...
- Linux Clone函数
Linux Clone函数 之前某一次有过一次面试,问了内核中是怎么创建命名空间的? 下面就来扒一扒clone的精髓,以及如何通过它创建命名空间. 目录 Linux Clone函数 使用clone创建 ...
- 配置 Docker 镜像加速源地址
docker 安装官方文档 根据实例的操作系统类型,参考相应的文档进行安装. 查看 linux 是 CentOS 还是 Ubuntu uname -a #查看系统信息 lsb_release -a # ...
- Linux 服务器安装node环境
Linux 装 node 环境 我的是 CentOS 查看服务器是多少位系统 getconf LONG_BIT 下载地址, 下载对应的版本: http://nodejs.cn/download/ 我这 ...
- 【Oracle】B-tree和函数索引
转自:https://www.cnblogs.com/yumiko/p/5957613.html 函数索引 1.1 概述 在实际应用中,当条件列使用函数运算进行数据匹配时,即使该列建立了索引,索引也不 ...
- CTFHub - Web(四)
最近又是每天忙到裂开,,,淦 xss: 反射型: 1.第一个输入框与下面Hello后的内容相同,猜测可以通过该输入,改变页面内容. 测试语句: <script>alert(1)</s ...
- 一. SpringCloud简介与微服务架构
1. 微服务架构 1.1 微服务架构理解 微服务架构(Microservice Architecture)是一种架构概念,旨在通过将功能分解到各个离散的服务中以实现对解决方案的解耦.你可以将其看作是在 ...
- 二十五:XSS跨站值原理分类及攻击手法
HTML DOM树 XSS跨站产生原理,危害,特点 本质,产生层面,函数类,漏洞操作对应层,危害影响,浏览器内核版本 XSS是什么? XSS全称跨站脚本(Cross Site Scripting),为 ...