ZOJ - 3865 Superbot (广搜)

MATLAB二维三维绘图进阶:从数据可视化到科研图表实战 数据可视化是连接复杂数学世界与人类直观认知的关键桥梁,其核心在于将抽象数据转化为直观图形,以揭示数据内在规律与趋势。在工程实践与科学研究中,高效的可视化不仅能提升数据分析效率,更是成果展示与学术交流的重要工具。MATLAB作为数学建模与科学计算的主流平台,其强大的绘图功能为数据可视化提供了完整解决方案。通过掌握二维绘图中的散点图、柱状图、等高线图等核心图表类型,以及三维绘图中的曲面图、网格图与空间曲线绘制技巧,用户可以精准呈现数据分布、清晰揭示变量关系,并高效传达研究洞察。本文聚焦于**MATLAB绘图** 阅读详情
Superbot

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Superbot is an interesting game which you need to control the robot on an N*M grid map.

As you see, it's just a simple game: there is a control panel with four direction left (1st position), right (2nd), up (3rd) and down (4th). For each second, you can do exact one of the following operations:

  • Move the cursor to left or right for one position. If the cursor is on the 1st position and moves to left, it will move to 4th position; vice versa.
  • Press the button. It will make the robot move in the specific direction.
  • Drink a cup of hot coffee and relax. (Do nothing)

However, it's too easy to play. So there is a little trick: Every P seconds the panel will rotate its buttons right. More specifically, the 1stposition moves to the 2nd position; the 2nd moves to 3rd; 3rd moves to 4th and 4th moves to 1st. The rotating starts at the beginning of the second.

Please calculate the minimum time that the robot can get the diamond on the map.

At the beginning, the buttons on the panel are "left", "right", "up", "down" respectively from left to right as the picture above, and the cursor is pointing to "left".

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains three integers N, M (2 <= N, M <= 10) and P (1 <= P <= 50), which represent the height of the map, the width of the map and the period that the panel changes, respectively.

The following lines of input contains N lines with M chars for each line. In the map, "." means the empty cell, "*" means the trap which the robot cannot get in, "@" means the initial position of the robot and "$" means the diamond. There is exact one robot and one diamond on the map.

Output

For each test case, output minimum time that the robot can get the diamond. Output "YouBadbad" (without quotes) if it's impossible to get the diamond.

Sample Input
4
3 4 50
@...
***.
$...
5 5 2
.....
..@..
.*...
$.*..
.....
2 3 1
*.@
$.*
5 5 2
*****
..@..
*****
$....
.....
Sample Output

12
4
4
YouBadbad

Hint

For the first example: 
0s: start
1s: cursor move right (cursor is at "right")
2s: press button (robot move right)
3s: press button (robot move right)
4s: press button (robot move right)
5s: cursor move right (cursor is at "up")
6s: cursor move right (cursor is at "down")
7s: press button (robot move down)
8s: press button (robot move down)
9s: cursor move right (cursor is at "left")
10s: press button (robot move left)
11s: press button (robot move left)
12s: press button (robot move left)

For the second example:
0s: start
1s: press button (robot move left)
2s: press button (robot move left)
--- panel rotated ---
3s: press button (robot move down, without changing cursor)
4s: press button (robot move down)

For the third example:
0s: start
1s: press button (robot move left)
--- panel rotated ---
2s: press button (robot move down)
--- panel rotated ---
3s: cursor move left (cursor is at "right")

--- panel rotated ---

题意:机器人从起点走到终点,不能走陷阱,每一秒机器人有三种操作

1 把游标向右或向左移动一个格子,如果游标在第一个位置,向左移动则到第四个位置

2 按下游标,按照游标此时的方向走一个格子

3 休息

每经过P秒,控制面板整体向右旋转一次

思路:很容易想到广搜,但是判断是否走过某一个点的时候不能只根据坐标来判断了,再加两个状态,在这一点游标所指的方向和p%t,再用一个pos变量来记录游标在控制面板的哪一个位置

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>

using namespace std;

char mp[15][15];
bool vis[15][15][10][55];
int sx,sy,ex,ey;
int n,m,p;
//控制面板上4种方向的顺序 
int to[4][4][2] = {0, -1, 0, 1, -1, 0, 1, 0,  
    1, 0, 0, -1, 0, 1, -1, 0,  
    -1, 0, 1, 0, 0, -1, 0, 1,  
    0, 1, -1, 0, 1, 0, 0, -1
};  

struct node{
	int x,y,dir,pos,step;
	node(){};
	node(int _x,int _y,int _dir,int _pos,int _step){
		this -> x = _x;
		this -> y = _y;
		this -> dir = _dir;
		this -> pos = _pos;
		this -> step = _step;
	}
};
//判断方向 
int judge(int x,int y){
	if(x == 0 && y == -1){
		return 0;
	}
	else if(x == 0 && y == 1){
		return 1;
	}
	else if(x == -1 && y == 0){
		return 2;
	}
	else if(x == 1 && y == 0){
		return 3;
	}
} 
bool check(int x,int y){
	if(x < 0 || y < 0 || x >= n || y >= m || mp[x][y] == '*'){
		return false;
	}
	return true;
}
void bfs(){
	queue<node> q;
	int nx,ny,ndir,npos,nstep;
	int ax,ay;
	q.push(node(sx,sy,0,0,0));
	vis[sx][sy][0][0] = 1;
	struct node temp;
	
	while(!q.empty()){
		temp = q.front();
		q.pop();
		
		if(temp.x == ex && temp.y == ey){
			printf("%d\n",temp.step);
			return;
		}
		
		//机器人走一个格子
		ax = to[(temp.step / p) % 4][temp.pos][0];
		ay = to[(temp.step / p) % 4][temp.pos][1];
		ndir = judge(ax,ay);
		nx = temp.x + ax;
		ny = temp.y + ay;
		npos = temp.pos;	
		nstep = temp.step + 1;	
		if(check(nx,ny) && !vis[nx][ny][ndir][nstep % p]){
			q.push(node(nx,ny,ndir,npos,nstep));
			vis[nx][ny][ndir][nstep % p] = 1;
		}
		
		//左移
		npos = (temp.pos - 1 + 4) % 4;
		ax = to[(temp.step / p) % 4][npos][0];
		ay = to[(temp.step / p) % 4][npos][1];
		ndir = judge(ax,ay);
		nx = temp.x;
		ny = temp.y;
		nstep = temp.step + 1;
		if(!vis[nx][ny][ndir][nstep % p]){
			q.push(node(nx,ny,ndir,npos,nstep));
			vis[nx][ny][ndir][nstep % p] = 1;
		}
		
		//右移
		npos = (temp.pos + 1 + 4) % 4;
		ax = to[(temp.step / p) % 4][npos][0];
		ay = to[(temp.step / p) % 4][npos][1];
		ndir = judge(ax,ay);
		nx = temp.x;
		ny = temp.y;
		nstep = temp.step + 1;
		if(!vis[nx][ny][ndir][nstep % p]){
			q.push(node(nx,ny,ndir,npos,nstep));
			vis[nx][ny][ndir][nstep % p] = 1;
		}
		
		//原地不动
		npos = temp.pos; 
		ax = to[(temp.step / p) % 4][npos][0];
		ay = to[(temp.step / p) % 4][npos][1];
		ndir = judge(ax,ay);
		nx = temp.x;
		ny = temp.y;
		nstep = temp.step + 1;
		if(!vis[nx][ny][ndir][nstep % p]){
			q.push(node(nx,ny,ndir,npos,nstep));
			vis[nx][ny][ndir][nstep % p] = 1;
		}

	}
	printf("YouBadbad\n");
}
int main(void){
	int t;
	scanf("%d",&t);
	
	while(t--){
		scanf("%d%d%d",&n,&m,&p);
		for(int i = 0; i < n; i++){
			scanf("%s",mp[i]);
			for(int j = 0; j < m; j++){
				if(mp[i][j] == '@'){
					sx = i;
					sy = j;
				}
				if(mp[i][j] == '$'){
					ex = i;
					ey = j;
				}
			}
		}
		memset(vis,false,sizeof(vis));
		bfs();
	}
}

TB6600驱动器共阴共阳接法傻傻分不清?一张图搞定STM32与42步进电机的接线避坑指南 本文详细解析了TB6600驱动器共阴共阳接法的本质区别,提供了STM32与42步进电机的高效连接方案。通过实际案例和接线图示,帮助读者避免常见错误,确保驱动器与MCU的安全连接,提升项目稳定性。 阅读详情

相关推荐

TEC半导体制冷片避坑指南:散热、电源与PID温控实战

半导体制冷片基于帕尔帖效应,通过直流电实现冷热面热量搬运,具备无运动部件、控温精度高的特点,但效率低、发热量大,对散热和电源要求苛刻。其技术价值在于小空间高精度温控,广泛应用于激光器、PCR仪、恒温箱等场景。然而,散热设计不良会导致冷面不冷,电源功率不足或纹波干扰会引发电流不稳,PID参数整定不当则造成温度震荡。此外,传感器位置、冷凝水防护和热循环应力也直接影响系统稳定性与寿命。本文结合万用表实测、散热选型与PID调参经验,系统梳理TEC应用中的典型问题与解决思路。

weixin_29191081的博客 308

zoj - Welcome Party(广搜+优先队列)

Welcome Party 思路: 首先找到所有集合中的最小值,可以用并查集,也可以用广搜,深搜就超时了, 然后把所有最小的值先存入有限队列,依次遍历队列就好了,但是要用邻接表,vector数组就超时╮(╯▽╰)╭。 #include<iostream> #include<cstdio> #include<cstring> #include...

积少成多,水滴石穿 216

MemSeg:一种差异和共性来检测图像表面缺陷的半监督方法

本文认为人为创建类内差异和保持类内共性可以帮助模型实现更好的缺陷检测能力,从而更好地区分非正常图像。如图一所示。差异(differences):MemSeg引入人工模拟的异常图像在训练阶段使模型能够区分正常和异常的图像,减轻了半监督学习只能用正常样本进行训练的不足,然后在推理阶段可以直接输入图像无需做任何后处理。共性(commonalities):MemSeg引入了一个记忆池来记录正常样本的通用模式,在训练和推理阶段,比较输入图像和记忆池中的样本之间的差异,为异常区域的定位提供有用的信息。

斯人若彩虹,遇上方知有! 4850

ZOJ-4020 Traffic Light(广搜 多次路径标记)

题意:在一张N*M的地图中只有1和0,0表示可以上下走,1表示可以左右走。每走一步地图上的1和0就会变化。输入一个起点和终点坐标,问起点到终点的最小步数。 第一反应是用广搜来写的,但是因为地图会变化。因此要用走到某个坐标的时间来判断是横着走还是竖着走,广搜可以直接模拟这个过程看能不能走到,而时间最短也是广搜可以实现的。因为题目中说明N*M小于1e5,因此用一个一位数组模拟二维数组。 然后要...

kuronekonano的博客 446

从补码原理到实践:RISC-V中addi指令的符号扩展机制详解

本文深入解析了RISC-V架构中addi指令的符号扩展机制。从补码的数学原理出发,详细阐述了12位立即数在指令编码中如何通过符号位进行扩展,并结合lui指令,揭示了加载任意32位立即数的正确方法与实践陷阱,帮助开发者编写高效可靠的底层代码。

weixin_29161719的博客 143

C51编程25-应用篇(单片机与电脑端实现wifi通讯)

单片机使用ESP-01S wifi模块与电脑端进行数据通讯。

qq_34343637的博客 1万+

zoj1005 广搜

本来挺简单的一道题,但是马虎wa了一次! 根据题意采取广搜的方法,代码有点长,但自我感觉思路挺清晰的! #include #include #include using namespace std; typedef struct fun { int pre; int a,b; int sign; }rr; fun s[10005]; void print(int j

生活总是要微笑着面对~ 679

用化学方法nmp溶剂从佳能cmos传感器上剥离拜耳矩阵和微透镜

将光刻胶暴露于 NMP 溶剂中 10-15 分钟,并进行轻微的机械搅拌,将溶解的光刻胶从基材表面带走,即可去除大部分光刻胶,之后再进行第二次溶剂浴,以洗去微量含有光刻胶的溶剂。我还担心传感器的校准问题,我觉得可以大致解决这个问题,比如在安装面上用刻度尺标记三个螺丝的位置,然后数着拧出螺丝的圈数,直到听到“咔哒”声(螺纹完全拧出)。我还担心传感器的校准问题,我觉得可以大致解决这个问题,比如在安装面上用刻度尺标记三个螺丝的位置,然后数着拧出螺丝的圈数,直到听到“咔哒”声(螺纹完全拧出)。在我看来,这是必读的;

qq_40247880的博客 1483

zoj3865

zoj3865 zoj3865 解题思路: 首先这道题求的是起点到终点之间的最短到达时间。我们可以维护一个三维的状态(x,y,direct),其中direct是光标指向的方向,可以理解为机器人robot是有方向的。光标所在的方向即为当前位置robot所面对的方向。如此一来,每一秒钟对于robot可以有四种操作: 朝着当前面对的方向前进一格,对应于题中按下一个按钮,机器人向对应方向移动

AndyTeen的专栏 847

图自编码器(GAE)与变分图自编码器(VGAE)

在学习图自编码器之前先了解一下自编码器与变分自编码器。

小鱼的小窝 1万+

Sigrity SystemSI仿真分析教程文件路径

为了方便读者能够快速上手和学会Sigrity SystemSI 的功能,将Sigrity SystemSI仿真分析教程专栏所有文章对应的实例文件上传至以下路径。

weixin_54787054的博客 724

zoj superbot (bfs)

/* 只不过状态用vis[20][20][4]来记录,每个点都有四个状态,访问过就不能访问 通过控制面板控制机器人找钻石,控制面板每p时间右移一次(队尾变队首),求最短路径 控制面板为左右上下的顺序,初始时 光标在左 有3种操作,占用一个单位时间 1. 光标左移(最左的移到最右)或者右移(最右的移到最左) 2.按按钮,机器人会根据光标所指的方向移动一个单位 3.停在原地 */ # in

苍竹林 521

锂电池SOH估计 | 锂电池SOH基础计算与可视化(Python)

锂电池SOH估计 | 锂电池SOH基础计算与可视化(Python)

前程算法屋的博客 903

ZOJ 3865 Superbot(广搜)

浙大校赛的一道搜索题。 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3865 题目大意:一个机器人,需要找到从起点到终点的最短路径,一共有四个选项分别代表上下左右(初始值为1左2右3上4下)每隔p秒这四个选项会对应的串动一位,而机器人只能走光标对应的方向。每秒钟你可以有四种可选动作: 1.按下按键并向你当

纳兰 580

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

zoj 3865 Superbot (广搜)

Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just a simple game: there is a control panel with four direction left (1st position), ri

芒果街上的小屋(此博客暂时停用) 649

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

ZOJ 3865 Superbot

Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just a simple game: there i

Song 699

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

ZOJ 3865 Superbot BFS

地图很小,根据题意BFS Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just

码代码的猿猿 1457

Superbot ZOJ - 3865(BFS)

Superbot 题目链接:ZOJ - 3865题意:一个N*M地图, 可以通过光标移动机器人, 使之找到钻石(@表示机器人初始位置, $表示钻石位置, *表示障碍, .表示空地),每p秒光标自动右移, 每秒一个操作,四个操作:1&gt; 按...

Sirius_han的博客 227

[bfs] zoj 3865 Superbot

题意: 给一个n*m的图。 '@'代表你的位置,'.'代表空地,'*'代表墙,'$'代表钻石。 在每一秒钟你有四种选择。 1、站着不动。 2、光标往左移动一格。 3、光标往右移动一格。 4、点击光标让自己按光标的方向移动一格。 然后题目还给了一个k,代表每k秒光标整体循环右移一格。 现在问你拿到钻石的最少步数。 思路: 本弱开了一个四维数组判重use[x][y][f][l]

Enmity_Dark 700

【 ZOJ- 3865】Superbot(BFS)

Superbotis an interesting game which you need to control the robot on anN*Mgrid map. As you see, it's just a simple game: there is a control panel with four direction left (1stposition), right ...

__似水流年__的博客 318

ZOJ3865:Superbot(BFS)

Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just a simple game: there is a control panel with four direction left (1st position), right

ACM!荣耀之路! 1323

Superbot ZOJ - 3865 (BFS)

Superbot ZOJ - 3865 Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's ju...

codeswarrior的博客 367

ZOJ-3865 Superbot

题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 题意: 机器人在地图中找钻石的游戏,给出一个地图,' * ' 表示墙,@表示起点,$表示钻石,移动方向取决于当前光标在哪个移动按钮上。 每秒可以左右移动一下光标位置或者按当前光标移动一下机器人或者什么都不做。 同时按钮在旋转,每len秒4个按钮向右旋转一

MyWorld 475

F - Superbot ZOJ - 3865

Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just a simple game: there is a control panel with four direction ...

海绵的博客 313
上一篇: Modular Inverse ZOJ - 3609 (扩展欧几里得算法)
下一篇: 浙江省赛 Mahjong Sorting(分类讨论)
hahahahhahello
博客等级 码龄9年 41粉丝 354原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值