[CCPC 2019] 厦门

2023-11-11

Description

Recently, Zayin became obsessed with a tower defense game called Arknights. The most special level is the 5th level of chapter 4: Don’t panic. The most special thing about this level is that an enemy will continue taking radioactive damage after passing through the Active Originiums. As the most handsome man in the world, he tried to put obstacles in various positions, making all the enemies to be killed before reaching the end. After many attempts, he finally won the three stars clearance award.
Interestingly, that night Zayin dreamt that he had become the King Slayer (the leader of enemies). In the dream, the map of the tower defense game becomes a cube with edge length n. Zayin can take a step forward, backward, up, down, left or right from his current position every second, but can’t get out of the map or walk through a grid of obstacles.
As in the original game, the player, who wants to kill all the enemies, can put obstacles many times. In particular, in the dream, every time players can place obstacles at all the coordinates (x,y,z) which satisfies a≤x≤d, b≤y≤e, c≤z≤f, and has no obstacles yet.
Now, Zayin knows that the player will place obstacles m times and the locations of each time. In order to avoid dying on the way, Zayin wants to go to the end as fast as possible. But unfortunately, Zayin got lost for so long that all the obstacles were placed. Now, Zayin asks you for help. Can you help him get out of the map as quickly as possible?

Input

The first line of input contains an integer T( 1 ≤ T ≤ 5 1≤T≤5 1T5), denoting the number of test cases.
Each test case starts with two integers n and m in a line, where n is the size of the map and m is the number of times the player puts obstacles. ( 1 ≤ n ≤ 100 , 1 ≤ m ≤ 1000 1≤n≤100, 1≤m≤1000 1n100,1m1000)
The next m lines contain six integers a,b,c,d,e,f in each line, denoting the range of obstacles the player puts. ( 1 ≤ a ≤ d ≤ n , 1 ≤ b ≤ e ≤ n , 1 ≤ c ≤ f ≤ n ) (1≤a≤d≤n, 1≤b≤e≤n, 1≤c≤f≤n) (1adn,1ben,1cfn)
Then there are six integers x 1 , y 1 , z 1 , x 2 , y 2 , z 2 x1,y1,z1, x2,y2,z2 x1,y1,z1,x2,y2,z2. The first three integers represent where Zayin is now, and the last three integers represent where the end point is.

Output

For each testcase, output an integer in a line, denoting how many seconds at least Zayin need to go to the end. If Zayin can’t go to the end, output -1.

Samples

Input Copy

3
3 0
1 1 1 3 3 3
3 1
2 1 1 2 3 3
1 1 1 3 3 3
3 3
2 1 1 2 2 3
1 1 2 2 3 2
1 2 2 3 3 2
1 1 1 1 1 3

Output

6
-1
14

Source

2019 CCPC xiamen onsite

根据容斥求出可以标记处三维空间中哪一块有障碍物,然后用三层for就可以枚举出

ll n,m,k;
int s[107][107][107],ss[107][107][107];
int stx,sty,stz,edx,edy,edz;
bool edge(int x,int y,int z){
	if(x < 1 || x > n) return false;
	if(y < 1 || y > n) return false;
	if(z < 1 || z > n) return false;
	return true;
}
struct node{
	int x,y,z;
};
int dx[6]={0,0,0,0,1,-1};
int dy[6]={0,0,1,-1,0,0};
int dz[6]={1,-1,0,0,0,0};
bool vis[107][107][107];
int dis[107][107][107];
void bfs(int x,int y,int z){
	queue<node> que;
	que.push({x,y,z});
	vis[x][y][z] = 1;
	dis[x][y][z] = 0;
	while(que.size()){
		node frt = que.front();
		que.pop();
		if(frt.x == edx && frt.y == edy && frt.z == edz) return ;
		for(int i=0;i<6;i++){
			int tx = frt.x + dx[i];
			int ty = frt.y + dy[i];
			int tz = frt.z + dz[i];
			if(ss[tx][ty][tz]) continue;
			if(!vis[tx][ty][tz] && edge(tx,ty,tz)) {
				que.push({tx,ty,tz});
				vis[tx][ty][tz] = 1;
				dis[tx][ty][tz] = dis[frt.x][frt.y][frt.z] + 1;
			}
		}
	}
	
}
int main() {
	int _ = read;
	while(_ --){
		memset(s,0,sizeof s);
		memset(ss,0,sizeof ss);
		memset(vis,0,sizeof vis);
		memset(dis,0,sizeof dis);
		n = read,m=read;
		for(int i=1;i<=m;i++){
			int a=read,b=read,c=read,d=read,e=read,f=read;
			s[a][b][c]--;
			s[a][b][f+1]++;
			s[a][e+1][c]++;
			s[a][e+1][f+1]--;
			s[d+1][b][c]++;
			s[d+1][b][f+1]--;
			s[d+1][e+1][c]--;
			s[d+1][e+1][f+1]++;
		}
		stx=read,sty=read,stz=read;
		edx=read,edy=read,edz=read;
		if(stx == edx && sty == edy && stz == edz) {
			puts("0");
			continue;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					ss[i][j][k]=(ss[i-1][j][k]+ss[i][j-1][k]+ss[i][j][k-1])-
					(ss[i-1][j-1][k]+ss[i-1][j][k-1]+ss[i][j-1][k-1])+ss[i-1][j-1][k-1]+s[i][j][k];
				}
			}
		}
		bfs(stx,sty,stz);
		if(dis[edx][edy][edz] >= 100000000 || dis[edx][edy][edz] == 0) {
			puts("-1");
		}else printf("%d\n",dis[edx][edy][edz]);
	}
	return 0;
}
/**
3
3 0
1 1 1 3 3 3
3 1
2 1 1 2 3 3
1 1 1 3 3 3
3 3
2 1 1 2 2 3
1 1 2 2 3 2
1 2 2 3 3 2
1 1 1 1 1 3

6
-1
14
**/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

[CCPC 2019] 厦门 的相关文章

  • 源码安装 nginx/1.15.8 的脚本

    环境是在centos7 下 其他环境还未试过 nginx 的安装路径在 usr local nginx bin bash 一般系统中已经装了了make和g 无须再装 yum y install autoconf automake make
  • 【通讯录--动态实现】

    目录 前言 一 功能设置 声明结构体 1 初始化 2 释放空间 3 添加联系人 4 删除联系人 5 查找联系人 6 修改联系人 7 显示联系人 8 清空联系人 9 排序联系人 二 整体代码 1
  • js的三种使用方式(行内js、内部js、外部js)

    1 行内js js不单独写出
  • 远程VirtualBox上的Linux虚拟机

    项目场景 为了能够隔离实验环境 在VirtualBox上安装了Centos7用来专门跑实验 却发现无法远程 关闭防火墙和SELinux 1 关闭防火墙 2 关闭SELinux getenforce 命令查看是否开启 若为 Enfocing
  • ERP系统设计:库存管理怎么做?

    库存是企业打算出售给客户以获取利润的商品或材料 库存管理是供应链的一个关键要素 涉及到从制造商到仓库 从这些设施到销售点的库存跟踪 库存管理的目标是在适当的时间将适当的产品放置在适当的地点 库存管理的业务问题 在进行库存管理工作时 会出现很
  • 基于Python的大数据分析基础(一)

    关于Pandas Pandas中的数据结构 1 Series 一维数组系列 也称序列 2 DataFrame 二维的表格型数据结构 3 Panel 三维数组 数据类型 1 Logical 逻辑型 2 Numeric 数值型 3 Charac
  • NodeJS简介-node.js是什么?

    Nodejs是个在服务器动可以解析和执行JavaScript代码的运行环境 也可以说是一个运行时平台 仍然使用JavaScript作为开发语言 但是提偶了一些功能性的API 例如文件操作和网络通信API等 Nodejs是由 Ryan Dah
  • ssh key authentication失败,查看日志是selinux禁止了sshd读取authorized_keys文件

    ssh key authentication失败 查看日志是selinux禁止了sshd读取authorized keys文件 May 5 04 24 36 localhost dbus 704 system Activating serv
  • C#的变迁史 - C# 4.0 之线程安全集合篇

    作为多线程和并行计算不得不考虑的问题就是临界资源的访问问题 解决临界资源的访问通常是加锁或者是使用信号量 这个大家应该很熟悉了 而集合作为一种重要的临界资源 通用性更广 为了让大家更安全的使用它们 微软为我们带来了强大的并行集合 Syste
  • 基于堆叠⾃编码器的时间序列预测 深层神经网络

    自适应迭代扩展卡尔曼滤波算法 AIEK 是一种滤波算法 其目的是通过迭代过程来逐渐适应不同的状态和环境 从而优化滤波效果 该算法的基本思路是在每一步迭代过程中 根据所观测的数据和状态方程 对滤波器的参数进行自适应调整 以便更好地拟合实际数据

随机推荐

  • python- NameError name ‘name‘ is not defined

    python NameError name name is not defined 练习写python函数的时候 遇到了NameError name name is not defined 这样的错误 百度了一下 发现name是一个系统变量
  • Selenium+Python系列 - 开发环境搭建

    优质资源分享 学习路线指引 点击解锁 知识定位 人群定位 Python实战微信订餐小程序 进阶级 本课程是python flask 微信小程序的完美结合 从项目搭建到腾讯云部署上线 打造一个全栈订餐系统 Python量化交易实战 入门级 手
  • 设计模式:代理模式

    由于某些原因需要给某对象提供一个代理以控制对该对象的访问 这时 访问对象不适合或者不能直接引用目标对象 代理对象作为访问对象和目标对象之间的中介 这就是代理模式 代理模式的主要优点有 1 代理模式在客户端与目标对象之间起到一个中介作用和保护
  • QT学习:制作树形列表菜单

    一 前言 使用QT制作树形的列表菜单 需要使用QTreeWidget和QTreeWidget两个类 最终效果如图所示 二 代码方式实现 使用代码方式实现树形菜单 首先要包含两个类库 include
  • 安全测试目录内容合集

    基础知识 安全测试基础知识 安全测试 django防御安全策略 HTTP工作原理 靶场DVWA 安全测试网站 DWVA下载安装启动 DVWA Command Injection DVWA 5 File upload 文件上传漏洞 DVWA
  • 【记录】安装Django 创建虚拟环境和新项目

    本文仅记录实际操作情况 本文参考书籍 1 2 1 确保电脑安装Python 2 创建虚拟环境 创建一个新目录test blog 再在终端中切换到这个目录 并执行如下命令创建一个虚拟环境 python m venv ll env 书上原文 这
  • 如何恢复内存卡数据?

    生活中 无论我们使用哪种存储设备 内部空间都是有限的 随着使用时间的增加 里面存储的数据会越来越多 这时如果不能及时处理 将很容易出现数据丢失 如果小伙伴们不小心碰到这样的事 要如何恢复内存卡数据呢 遇到了请不要着急 下面小编就分享可以有效
  • python读取表格画散点图_Note: Python_Matplotlib绘制平滑曲线和散点图

    给出横坐标纵坐标点 即可连线绘图 import matplotlib 调用绘图工具包 给出x y点坐标 x y 1 2 3 4 5 6 5 9 3 4 7 5 绘图 matplotlib pyplot plot x y 这样使用工具包如果程
  • python发邮件附件内容中文乱码_python3发邮件,附件名称为中文时出错

    问题描述 我写了一个发邮件的类 一切进行的很顺利 但是附件名改成中文的时候就出问题了 问题出现的环境背景及自己尝试过哪些方法 用的是python3 和email包 是了MIMEText MIMEApplication MIMEBase都不行
  • java scope_spring中的scope详解

    1 singleton 单一实例 此取值时表明容器中创建时只存在一个实例 所有引用此bean都是单一实例 如同每个国家都有一个总统 国家的所有人共用此总统 而这个国家就是一个spring容器 总统就是spring创建的类的bean 国家中的
  • Flask框架种使用ORM模型对MySQL数据库的管理

    通过flask连接MySQL数据库后 使用ORM模型对数据库管理 ORM模型的优点 使用 ORM 做数据库的开发可以有效的减少重复SQL语句的概率 写出来的模型也更加直观 清晰 支持多个关系数据库引擎 包括流行的 MySQL Postgre
  • mysql使用st_distance_sphere函数报错Incorrect arguments to st_distance_sphere

    最近发现执行mysql st distance sphere报错了 报错的信息是Incorrect arguments to st distance sphere 最开始以为是跟mysql的版本有关系 所以看了下自己本地的mysql版本 执
  • 详解shell输出重定向:>/dev/null 2>&1

    1 输入输出重定向介绍 重定向简单来说就是把本来已经默认的 确定的输入输出给重新定位到你想要的地方 重定向这个概念在C语言中就有 在C语言编程中 标准输出是屏幕 使用printf 函数默认是输出到屏幕显示 但是有时候我们需要将信息输出到文件
  • BOM特效:返回顶部按钮

    BOM特效开发 返回顶部按钮制作 BOM特效开发 返回顶部按钮制作 改变document documentElement scrollTop属性 结合定时器逐步改变此值以动画形式返回顶部 在这里插入代码片
  • 基于HAL库的FREERTOS-----------三.队列

    一 队列简介 在实际的应用中 常常会遇到一个任务或者中断服务需要和另外一个任务进行 沟通交流 这个 沟通交流 的过程其实就是消息传递的过程 在没有操作系统的时候两个应用程序进行消息传递一般使用全局变量的方式 但是如果在使用操作系统的应用中用
  • STM32学习笔记---TIM_GetFlagStatus和TIM_GetITStatus两个固件库函数的区别

    TIM GetFlagStatus和TIM GetITStatus两个函数的区别 最近结合正点原子基于STM32F103ZET6芯片开发板的触摸按键实验 在对TIM5 CH2捕获状态进行判断时发现利TIM GetFlagStatus和TIM
  • [C++]适配器模式

    适配器模式 Adapter Pattern 是作为两个不兼容的接口之间的桥梁 这种类型的设计模式属于结构型模式 它结合了两个独立接口的功能 github源码路径 https github com dangwei 90 Design Mode
  • Oracle insert all 详解

    文章目录 1 概述 2 insert 的两种形式 2 1 insert first 2 2 insert all 3 数据一致性 同时插入 3 1 验证 insert into 数据不一致 3 2 验证 insert all 数据一致 1
  • Clang Static Analyzer 系列(一)编译 Clang 及运行 Checker

    编译 Clang CSA Clang Static Analyzer 是 clang 的一部分 建议使用自行编译的 clang 源码在 llvm llvm project github com 上获取 编译 clang 前首先要生成 cla
  • [CCPC 2019] 厦门

    Description Recently Zayin became obsessed with a tower defense game called Arknights The most special level is the 5th