Superbot ZOJ - 3865 (BFS)

天线学习笔记——HFSS简单阵列天线 在HFSS15.0版本中使用 Radiation --> Antenna Array Setup 设置天线阵列的参数时的设计列表如下: 值得注意的是,在该版本中所定义的是:第一个阵元的位置坐标(First Cell Position)、阵元之间的间距(Directions)和阵元的数量(Number of Cells) 这些参数。 在ANSYS中的HFSS仿真中定义天线阵列如下: 与老版本不同的是:中心点坐标(Center Position)和布局设置(Layout Setting)。在布局设置中 阅读详情

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 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 1st position 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 ---
4s: press button (robot move left)


有t组输入

每组输入n, m, p。表示一个n*m的地图,每p秒按键会右移一次(这个等会儿再讲)。

然后是地图的输入。其中'@'为起点,'$'为终点,'.'为通路,'*'为不通。

问从起点到终点最少需要多久?

注意!

每一秒有4种操作,注意,不是三种,1. 光标左移,2. 光标右移,3. 按照光标方向行走,4. 不动(尤其是这一个)。

所谓光标左移,右移,因为题目中给出了光标(在图上,共4个方向),每次改变的移动方向只能是当前光标选择的方向的左右两个。而行走只能按照光标所指的方向。

另外每过p秒,方向会变化(初始四个方向的顺序为左右上下,p秒后变成右上下左,再过p秒后变为上下左右)。

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int N = 20;
struct node{
    int x,y,dir,t;
};
int go[4][2] = {{0,-1},{0,1},{-1,0},{1,0}};
int n,m,P;
char mp[N][N];
bool vis[N][N];
bool vvis[N][N][5];
int change(int a){
    switch(a){
    case 0:
        return 3;
    case 1:
        return 0;
    case 2:
        return 1;
    case 3:
        return 2;
    }
}
void bfs(){
    node p;
    bool flag = false;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(mp[i][j] == '@'){
                p.x = i;
                p.y = j;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }
    p.dir = 0;
    p.t = 0;
    vvis[p.x][p.y][p.dir] = 1;
    queue<node>que;
    que.push(p);
    while(!que.empty()){
        p = que.front();
        que.pop();
        int xx = p.x + go[p.dir][0];
        int yy = p.y + go[p.dir][1];
        if(xx >= 0 && xx < n && yy >= 0 && yy < m){
            if(!vis[xx][yy]){
                if(mp[xx][yy] == '.'){
                    vis[xx][yy] = 1;
                    node q;
                    q.x = xx;
                    q.y = yy;
                    q.t = p.t + 1;
                    q.dir = p.dir;
                    if(q.t % P == 0){
                        q.dir = change(q.dir);
                        vvis[xx][yy][q.dir] = 1;
                    }
                    que.push(q);
                }
                else if(mp[xx][yy] == '$'){
                    printf("%d\n",p.t + 1);
                    return;
                }
             }
        }
        if((p.t + 1) % P == 0)
            p.dir = change(p.dir);
        node q;
        q.x = p.x;
        q.y = p.y;
        q.t = p.t + 1;

        q.dir = (p.dir + 1) % 4;
        if(!vvis[q.x][q.y][q.dir]){
            que.push(q);
            vvis[q.x][q.y][q.dir] = 1;
        }
        q.dir = (p.dir + 3) % 4;
        if(!vvis[q.x][q.y][q.dir]){
            que.push(q);
            vvis[q.x][q.y][q.dir] = 1;
        }
        q.dir = p.dir;
        if(!vvis[q.x][q.y][q.dir]){
            que.push(q);
            vvis[q.x][q.y][q.dir] = 1;
        }
    }
    printf("YouBadbad\n");
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        memset(vis,0,sizeof(vis));
        memset(vvis,0,sizeof(vvis));
        scanf("%d%d%d",&n,&m,&P);
        for(int i = 0; i < n; i++){
            scanf("%s",mp[i]);
        }
        bfs();
    }
    return 0;
}

Thingsboard PE智慧运维仪表板实例(一)【智慧排口截污实例】 以该实际落地项目为案例,跟着我一起搭建智慧运维大屏!社区版和专业版都通用。本文是致力于快速搭建,所以不会详细去讲Thingsboard的知识点,只讲如何配置和使用部件。 阅读详情

相关推荐

告别手动拍照!用Python+JAKA机械臂+D455相机实现全自动手眼标定(附完整代码)

本文详细介绍了如何利用Python脚本实现JAKA机械臂与Intel RealSense D455相机的全自动手眼标定流程,提供从硬件配置到代码实现的完整解决方案。通过自动化标定,显著提升工业自动化中的精度和效率,适用于机器人视觉领域的二次开发需求。

weixin_30555125的博客 521

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

码代码的猿猿 1454

头歌平台-人工智能导论实验(人脸识别)

答案仅供参考,自己动手丰衣足食!!!

qq_52119136的博客 3026

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!荣耀之路! 1320

vivado2020.1使用vitis生成QSPI启动文件报错

在使用vivado2020.1使用vitis,生成QSPI启动文件时会报错,data2mem命令无法识别,这是因为data2mem是xilinx7series芯片的命令,当使用ultrascale/ultrascale+芯片时则需要使用updatemem命令,这或许是vitis的一个bug吧,明明选择的是ultrascale的芯片,却一直调用打她mem命令,挺麻烦的,需要手动执行,在XSCT console窗口执行的命令如下: updatemem -force -meminfo \ F:/xc7z35t/x

qq_32134427的博客 2336

基于ESP32 蓝牙游戏手柄设计

介绍使用 ESP32 并通过 BLE 通信的 设计手持游戏手柄,包含原理图与代码

DT程序员的博客 2163

【 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 ...

__似水流年__的博客 314

GEE:面对对象土地利用分类(结合SNIC、GLCM 和机器学习算法)

本文将介绍在Google Earth Engine中结合SNIC、GLCM和机器学习算法的的土地利用/土地覆盖(LULC)分类方法。结果如下图所示,

养乐多的博客 5613

ZOJ 3865 - Superbot(BFS)

题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 题意: 给你一个n*m的地图,求出从@走到$的最小时间.使用按钮去控制人走的方向. 四个按钮的初始位置是(左,右,上,下).每p秒按钮会向右移动变成(下,左,右,上). 思路: BFS. vis[x][y][按钮方向][时间] 记录走过的位

Halo 812

解决pd.read_json报错ValueError: Trailing data问题

首先,我们使用open函数打开JSON文件,然后使用json.load函数将JSON文件数据解码为Python对象。在使用Python进行数据处理中,我们经常需要将JSON格式的数据读入到DataFrame中进行处理。而使用pandas库的read_json函数,就可以方便地将JSON数据读入到DataFrame中。但是有时候在读取JSON数据时,会遇到一个非常常见的错误:ValueError: Trailing data。这个错误的解决方案并不难,只需要在read_json中添加一个参数即可。

学习使你进步。 2234

ESP32-C3模组上跑通OTA升级(3)

ESP32-C3模组上跑通OTA升级(3)

phmatthaus的专栏 1351

(BFS)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 gam

better_life30的专栏 458

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

[bfs] zoj 3865 Superbot

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

Enmity_Dark 699

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Superbot ZOJ - 3865(BFS)

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

Sirius_han的博客 225

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

BFS+模拟 ZOJ 3865 Superbot

题目传送门 1 /* 2 BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少; 3 BFS分4种情况入队,最后在终点4个方向寻找最小值:) 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <al...

weixin_34392843的博客 64

ZOJ - 3865 Superbot 【BFS】

题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3865 思路 一个迷宫题 但是每次的操作数和普通的迷宫题不一样 0.按下按钮 即向当前方向盘的方向前进一格 1.往左移动方向盘 2.往右移动方向盘 3.不动 然后记录时间 易知,可以从四个方向到达终点,最后从这四个方向找最小值就是答案 当然要判...

Dup4'Blog 252

ZOJ 3865 Superbot(BFS)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3865 题意:给你一个n*m的地图,求出从@走到$的最小时间.使用按钮去控制机器人走的方向; 四个按钮的初始位置是:左右上下,每隔P秒按钮就会向右移动,变成:下左右上、上下左右、右上下左…… 思路: 为了简化按钮的移动步骤,我们直接用二进制给四个位置标记,1

Yedl的专栏 701

ZOJ 3865 Superbot(BFS水题)

比赛的时候题意理解错了,不想多说什么了。。 水题一道,,给你四个按钮,每次你可以选择不动,左右移动按钮,按钮每P秒右移一次,,水啊 #include "stack" #include "cstdio" #include "iostream" #include "cmath" #include "set" #include "sstream" #include "cctype" #

潮鸣り 401

zoj 3865 Superbot(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. Superbot是需要你在一个N*M的网格地图里控制机器人的有趣游戏。

24小时的程序员 672

zoj.3865.Superbot(bfs + 多维dp)

SuperbotTime Limit:2 Seconds Memory Limit:65536 KB 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 co...

weixin_30379911的博客 81

浙江大学2015年校赛F题 ZOJ 3865 Superbot BFS 搜索

不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4}; 我定义了一个方向数组,其实题目意思中的,指针移动还有操作版的变化本质上都是指针的移动 在此只需要 额外定义一个变量 cur 在数组 commandi 中循环移动即...

weixin_30540691的博客 195

zoj 3865 Superbot 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 a simple game: t

我的指针和我一样找不到对象 1333

ZOJ3865:Superbot(BFS) The 15th Zhejiang University Programming Contest

一个有几个小坑的bfs 题目很长,但并不复杂,大概总结起来有这么点。 有t组输入 每组输入n, m, p。表示一个n*m的地图,每p秒按键会右移一次(这个等会儿再讲)。 然后是地图的输入。其中'@'为起点,'$'为终点,'.'为通路,'*'为不通。 问从起点到终点最少需要多久? 一眼看去,裸的bfs嘛,10*10的地图,简单! 不过还是连错4次…… 注意! 每一秒有4种操作...

weixin_30894583的博客 105

ZOJ 3865 Superbot

解题思路: 简单的bfs, 记录一下当前的键盘状态。 #include #include #include #include #include #include #include #include #include #include #define ll long long using namespace std; int Move[][2] = { {0, -1}, {0

蘑菇--走在通往梦想的道路上。 559
上一篇: GCD Expectation ZOJ - 3868 (容斥原理+快速幂)
下一篇: Teams Formation CodeForces - 878B (思维+模拟)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值