首页 > 其他分享 >第六场问题 F: GlitchBot(模拟)

第六场问题 F: GlitchBot(模拟)

时间:2023-05-26 15:00:32浏览次数:43  
标签:第六场 int state robot step GlitchBot Forward 模拟 instructions


传送门

题目描述

One of our delivery robots is malfunctioning! The job of the robot is simple; it should follow a list of instructions in order to reach a target destination. The list of instructions is originally correct to get the robot to the target. However, something is going wrong as we upload the instructions into the robot’s memory. During the upload, one random instruction from the list takes on a different value than intended. Yes,there is always a single bad instruction in the robot’s memory and it always results in the robot arriving at an incorrect destination as it finishes executing the list of instructions.
The robot can execute the instructions “Left”, “Right”, and “Forward”. The “Left” and “Right” instructions do not result in spatial movement but result in a 90-degree turn in the corresponding direction. “Forward” is the only instruction that results in spatial movement, causing the robot to move one unit in the direction it is facing. The robot always starts at the origin (0, 0) of a grid and faces north along the positive y-axis.
Given the coordinates of the target destination and the list of instructions that the robot has in its memory, you are to identify a correction to the instructions to help the robot reach the proper destination.

 

输入

The first line of the input contains the x and y integer coordinates of the target destination, where −50 ≤ x ≤ 50 and −50 ≤ y ≤ 50. The following line contains an integer n representing the number of instructions in the list, where 1 ≤ n ≤ 50. The remaining n lines each contain a single instruction. These instructions may be: “Left”, “Forward”, or “Right”.

 

输出

Identify how to correct the robot’s instructions by printing the line number (starting at 1) of an incorrect input instruction, followed by an instruction substitution that would make the robot reach the target destination. If there are multiple ways to fix the instructions, report the fix that occurs for the earliest line number in the sequence of instructions. There is always exactly one unique earliest fix.

 

样例输入

复制样例数据


3 2 11 Forward Right Forward Forward Left Forward Forward Left Forward Right Forward


样例输出


8 Right


就按照题意模拟就行了,数据范围也不大,比赛的时候一个队友去模拟,没有模拟出来。

#include<bits/stdc++.h>
using namespace std;
const int MAX = 60;
const int f = -1,l = 0,u = 1,r = 2,d = 3;
const int cx[] = {-1, 0, 1, 0};
const int cy[] = {0, 1, 0, -1};
int ex, ey, n;
struct Step
{
    int oper;
    int state;
    int x, y;
};
Step step[MAX];
bool walk(int x, int y, int number, int state)
{
    for(int i = number; i < n; i++)
    {
        if(step[i].oper == f)
        {
            x += cx[state];
            y += cy[state];
        }
        else if(step[i].oper == r)
            state = (state + 1) % 4;//顺时针
        else
            state = (state + 4 - 1) % 4;//逆时针
    }
    return (x == ex && y == ey);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string str;
    while(cin >> ex >> ey)
    {
        cin >> n;
        int x = 0, y = 0, state = u;
        for(int i = 0; i < n; i++)
        {
            cin >> str;

            step[i].x = x, step[i].y = y, step[i].state = state;
            if(str == "Forward")
            {
                step[i].oper = f;
                x += cx[state];
                y += cy[state];
            }
            else if(str == "Right")
            {
                step[i].oper = r;
                state = (state + 1) % 4;//顺时针
            }
            else
            {
                step[i].oper = l;
                state = (state + 4 - 1) % 4;//逆时针
            }
        }

        for(int i = 0; i < n; i++)
        {
            if(step[i].oper != f && walk(step[i].x + cx[step[i].state], step[i].y + cy[step[i].state], i + 1, step[i].state))
            {
                cout << i + 1 << " Forward" << endl;
                break;
            }
            if(step[i].oper != l && walk(step[i].x, step[i].y, i + 1, (step[i].state + 4 - 1) % 4))
            {
                cout << i + 1 << " Left" << endl;
                break;
            }
            if(step[i].oper != r && walk(step[i].x, step[i].y, i + 1, (step[i].state + 1) % 4))
            {
                cout << i + 1 << " Right" << endl;
                break;
            }
        }
    }
    return 0;
}

 

标签:第六场,int,state,robot,step,GlitchBot,Forward,模拟,instructions
From: https://blog.51cto.com/u_16131191/6356136

相关文章

  • HCL华三模拟器BGP配置更新源
    peerconnect-interface命令用来指定与对等体/对等体组创建BGP会话时建立TCP连接使用的源接口,即采用指定源接口的IP地址/IPv6地址与对等体/对等体组建立TCP连接。本命令的作用与peersource-address命令的作用类似:peersource-address命令直接指定建立TCP连接的源地址;本命令通过......
  • 算法学习记录(模拟枚举贪心题单):四舍五入(未AC)
    题目链接https://ac.nowcoder.com/acm/contest/20960/1004题目分析注意当第i位为9是,此时进位就是0,但是0<5,所以就不能再用i+1进行判断了。所以对于这种情况可以再添加一个其他变量。未AC代码//主要解决问题,因为使用i+1去判断是否要进位的//逢9进位后就会变成0,那么第i+1位......
  • FLEX实践—模拟Application与Module间的事件监听
         一直找到如何在Application中发出一个事件,让Module捕获该事件并做出相应的动作。但是一直没找到,于是模拟了一个这样的情景。 WatchTest.mxml<?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"......
  • 2023冲刺国赛模拟 4.1
    T1宝石需要统计每种方案中所含宝石的种类数之和,考虑对于每种宝石分开统计,设当前考虑了第\(i\)种宝石,容易发现只需要统计包含这种宝石的方案数,因为对每种宝石的方案数求和就是答案。包含的情况不好考虑,考虑求解不包含这种宝石的方案数,设包含这种宝石的节点构成集合\(S\),容易......
  • 基于Matlab模拟毫米波雷达接收发射信号仿真
    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。......
  • 冲刺国赛模拟 4
    牛子老师认为xmz回来了他终于有打的原因了,这就是神吗!T1挂了45,又垫底了!突然发现tlecoders和题库考试都叫冲刺国赛模拟。那到时候url好像会重。宝石首先套路拆成每个颜色的贡献。然后对于每个颜色分开考虑,用全部方案减掉没有这个颜色的方案。这个容易统计,可以对于每个不......
  • R语言SIR模型网络结构扩散过程模拟SIR模型(Susceptible Infected Recovered )代码实例|
    全文链接:http://tecdat.cn/?p=14593最近我们被客户要求撰写关于SIR模型的研究报告,包括一些图形和统计输出。与普通的扩散研究不同,网络扩散开始考虑网络结构对于扩散过程的影响。这里介绍一个使用R模拟网络扩散的例子基本的算法非常简单:生成一个网络:g(V,E)。随机选择一个或几......
  • 尝试讲解一下数字电路和模拟电路的状态方程
        状态方程,也称为状态转移方程。在数字电路的时序逻辑分析和设计中,会用到状态方程。而实际模拟电路中几乎不用,用到的是“电路分析”部分。但是自动控制原理,通常是通过模拟电路实现的,而使用状态方程的方法,通常被称为现代控制理论。这里不研究那么高深的自动控制理论,仅仅......
  • 2023冲刺国赛模拟 7.0
    T1Matrix很容易想到一个\(O(n^4)\)做法,用uint128压位,然后你发现它过了……正解考虑分治,取出矩阵中间的列\(mid\),由于跨越\(mid\)列的询问必然经过\(mid\)列上一点,因此对于\(mid\)左边的点,预处理每个点向右,向下可以到达的所有\(mid\)处的点,对于\(mid\)右边的点,......
  • 8AI模拟量采集模块支持上位机采集
    MxxxT工业远程以太网I/O数据采集模块是一款高性能的工业设备,它内嵌了32位的微处理器MCU,并集成了1个工业级的10/100M自适应以太网接口,支持标准的Modbus协议,具备良好的扩展性和丛机寄存器映射功能。这些特性使MxxxT远程I/O模块在数字化生产中有着广泛应用。首先,MxxxT......