HDU 1035 - Robot Motion

Keil5 编译警告:单精度转双精度问题解决方案 通过在浮点数常量后添加 f 后缀,我们可以明确指定其为单精度类型,从而消除编译警告,同时提高代码的执行效率。这是一个简单但重要的编程细节,特别是在资源受限的嵌入式系统开发中。 阅读详情

Robot Motion

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5352    Accepted Submission(s): 2492


Problem Description


A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are 

N north (up the page)
S south (down the page)
E east (to the right on the page)
W west (to the left on the page)

For example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid.

Compare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits.

You are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around.
 

Input
There will be one or more grids for robots to navigate. The data for each is in the following form. On the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. The possible entry columns are numbered starting with one at the left. Then come the rows of the direction instructions. Each grid will have at least one and at most 10 rows and columns of instructions. The lines of instructions contain only the characters N, S, E, or W with no blanks. The end of input is indicated by a row containing 0 0 0.
 

Output
For each grid in the input there is one line of output. Either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word "step" is always immediately followed by "(s)" whether or not the number before it is 1.
 

Sample Input
3 6 5 NEESWE WWWESS SNWWWW 4 5 1 SESWE EESNW NWEEN EWSEN 0 0
 

Sample Output
10 step(s) to exit 3 step(s) before a loop of 8 step(s)
 


==============================

简单的模拟

当一个点走过两次就说明一定会一直重复走下去


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
char map[1111][1111];
int vis[1111][1111];
int n,m,s;

bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m) return 1;
    else return 0;
}

int main()
{
    while(~scanf("%d%d%d",&n,&m,&s))
    {
        if(n==0&&m==0&&s==0) break;
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
            scanf("%s",map[i]+1);
        int x=1,y=s;
        int temp=0,ans=0,cnt=0,flag=0;
        while(check(x,y))
        {
            ans++;
            //cout<<x<<" "<<y<<" "<<ans<<endl;
            if(!vis[x][y]) vis[x][y]=1;
            else if(vis[x][y]==1)
            {
                vis[x][y]=2;
                cnt++;
                if(!flag)
                {
                    temp=ans;
                    flag=1;
                }
            }
            else if(vis[x][y]==2) break;
            if(map[x][y]=='N') x-=1;
            else if(map[x][y]=='S') x+=1;
            else if(map[x][y]=='W') y-=1;
            else if(map[x][y]=='E') y+=1;
        }
        if(!check(x,y))
            printf("%d step(s) to exit\n",ans);
        else
            printf("%d step(s) before a loop of %d step(s)\n",temp-cnt-1,cnt);
    }
    return 0;
}


main.c(274): warning: #1035-D: single-precision operand implicitly converted to double-precision 0.0008改为0.0008f试试看,arm的编译器通常在计算浮点数乘除法时转成双精度的计算,其实可以强制转化为float去计算,这样还可以减少代码空间,增加程序执行效率 ... 阅读详情

相关推荐

全网最详细 解决戴维南定理的详细推导

替代定理,戴维南定理详细证明

m0_52555753的博客 3万+

#1035-D: single-precision operand implicitly converted to double-precision

keil编译C++代码时,出现警告:#1035-D: single-precision operand implicitly converted to double-precision float代表浮点型数据类型,浮点型数据又分为单精度和双精度两种,1.0小写f或者大写F代表他是单精度的,如果1.0后面跟的是小写d后者大写D代表他是双精度的。 可以忽略这个警告,也可以在所有的浮点数字后面加上f,警告就会消失。比如:floata=1.01f; ...

reason的博客 2万+

An工具介绍之摄像头

An工具介绍之摄像头

人生得意须尽欢 6187

POJ 1573 && hdu 1035 Robot Motion【简单模拟】

题目链接:http://poj.org/problem?id=1573                    http://acm.hdu.edu.cn/showproblem.php?pid=1035 Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot

free斩 1611

高可用架构设计——多节点OpenClaw集群部署与负载均衡(2026企业级)

本文介绍了企业级OpenClaw高可用集群架构设计,重点阐述了多节点部署与负载均衡方案。架构采用分层设计,包括表现层、应用层、数据层和基础设施层,确保99.99%的可用性目标。详细配置了主节点、工作节点和存储节点规格,提供Kubernetes集群部署脚本示例,实现自动化的容器编排管理。通过硬件冗余、故障隔离和弹性扩展等可靠性原则,构建能够应对各种故障场景的稳定AI助手系统。

博客 421

手把手教你学Simulink——基于Simulink的滑模控制器车辆稳定性仿真建模示例

本文详细介绍了基于Simulink的滑模控制器在车辆稳定性控制中的应用。通过建立二自由度车辆动力学模型(含魔术公式轮胎),设计横摆角速度与质心侧偏角滑模控制器,在Simulink中实现直接横摆力矩控制。文章包含完整的建模流程:从参考模型设计、滑模控制器推导(含等效控制和边界层法),到MATLAB参数设定和Simulink模块搭建。通过双移线测试和路面突变场景验证,证明该控制器能在低附着路面(μ=0.3)将横摆角速度误差控制在±5%以内,显著提升车辆稳定性。同时提供了工程实践要点和扩展方向(如高阶滑模、自适应

MHD0815的博客 106

freezing robot problem

“freezing robot” problem: once the environment surpasses a certain level of complexity, the planner decides that all forward paths are unsafe, and the robot freezes in place (or performs unnecessary m...

xp1994816的博客 1019

python乘法运算 信息素养大赛复赛/决赛真题 小学组/初中组 python编程挑战赛 真题详细解析

本文解析了全国青少年信息素养大赛Python编程挑战赛的乘法运算题目。题目要求通过递归算法实现两个自然数的乘法运算,并输出算式。算法分析指出可将乘法转化为累加,使用递归函数实现。程序代码展示了一个自定义函数add(),通过递归调用完成累加运算。文章还分析了考点,包括递归函数、输入处理、分支语句等编程基础知识的应用。最后强调解题方法的多样性,重点在于理解递归原理和实现题目要求。该题目难度适中,主要考查选手对递归算法的理解和编程基础能力。

青少年编程学习指导 789

杭电 hdu 1035 Robot Motion

嘿嘿,一次AC……哦耶~~~ 总得来说不算是难题,不过在处理坐标的时候出了问题,呃,这个代码中会有略微提到,因为比较简单,就不多说了,相信通过自己测试数据,也能理解的。   /* THE PROGRAM IS MADE BY PYY */ /*--------------

panyanyany(飞雨幻沙) 1203

在 SAP 世界里拥抱非 SAP 技术:一名 ABAP 开发者的成长路径与实战方法论

那段时间非常煎熬,但它带来的回报也很真实:你会更尊重“可观测性”的价值,也会更愿意在 SAP 场景里把日志、追踪、断言、隔离测试做扎实。解决这类问题,靠的并不是某个神奇的 SAP 函数,而是跨栈的工程设计:接口要有业务幂等键,SAP 侧要有落库与锁策略,返回要有可识别的状态码,异常要能回放,补偿要有可追踪的工单或队列。这套体系吸引我的地方,在于它更贴近真实业务:客户要的往往不是“能打印”,而是“能规范地输出”,包括版式、字体、条码、二维码、电子签章位置、分页规则、多语言、合规水印、可回写的交互字段等。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 167

基于MATLAB Simulink的电动汽车整车控制仿真

在本文中,我们选择了power_ElectricVehicle示例模型,该模型已经包含了电动汽车的基本组成部分,包括电机、变速器、驱动轮、电池等。例如,使用PID控制器来控制电机的转速,使用ABS控制器来控制车轮的制动力,使用转向控制器来控制车辆的转向角度,使用悬挂控制器来控制车轮的姿态等。通过建立模型和实现控制器,我们可以比较直观地了解电动汽车的工作原理和性能特点,并验证设计的控制系统在不同工况下的效果。而在电动汽车的开发中,整车控制系统是至关重要的一个组成部分,直接影响着电动汽车的性能和性价比。

qq_39605374的博客 1800

hdu 1035 Robot Motion

hdu 1035 Robot Motion         深搜。 #include #include #define MAX_N 11 char map[MAX_N][MAX_N]; int visited[MAX_N][MAX_N]; int n, m; int sx, sy; int step, loopStep; bool dfs(int x, int

happen_zhang 893

R语言生存分析之竞争风险模型

R语言生存分析之竞争风险模型 竞争风险模型(Competing Risk Model)是一种处理多种潜在结局生存数据的分析方法,早在1999年Fine和Gray就提出了部分分布的半参数比例风险模型,通常使用的终点指标是累积发生率函数(cumulative incidence function,CIF)。 研究中结局事件可能有多个,某些结局将阻止感兴趣事件的出现或影响其发生的概率,各结局事件形成“竞争”关系,互为竞争风险事件。 竞争风险模型( Competing Risk Model ) : 指

data+scenario+science+insight 5247

HDU-1035 Robot Motion

HDU-1035 Robot Motion 题目链接:HDU-1035 题目大意:判断机器人能否从区域内走出去,如果能,输出他需要走的步数,如果不能走出在里面陷入了循环,输出一次循环的次数以及进入循环前走的步数 解题思路:运用map集合的特性 将位置设为key 将从起点开始到当前位置的步数作为value 进去死循环即可 如果到了边界就跳出来输出最大步数 如果进入循环就输出循环起点的步数(通过ma...

鱼头的水题之路 219

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

hdu 1035 robot motion

题目的意思就是给一个初始位置,按着指示往下走,计算出走出方格的步数 或者遇到循环的圈子计算圈子的步数和到达圈子的步数#include using namespace std; struct node { char instr; //指示方向 int step; //步骤 }; node Arr[11][11]; int iN,iM,istart_pos; //row,column,开始

水神 533

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

HDU ACM1035——Robot Motion

Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible ins...

BarisGuo的博客 324

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

HDOJ(HDU).1035 Robot Motion (DFS)

HDOJ(HDU).1015 Robot Motion [从零开始DFS(4)]点我挑战题目题意分析给出地图规模n * m, 给出入口坐标(0,y),遵循以下规则,求解机器人能否走出地图。若能,输出走出地图所需要的步数,若不能,输出进入循环前走的步数和循环的步数。规则: 若当前格子为N,则只能向上走,若为S向下走,E向右走,W向左走。我第一感觉是模拟题,因为对于每个格子状态是唯一的,只有1组解:要

Pengwill's Blog 1074

hdu1035Robot Motion

题目大意:就是给你一张图,然后你根据每次所在的位置的那个要求走下一步,出界条件就是结束的条件,否则如果进入循环你要输出你是经过几步到达这个循环的,并且这个循环有几步,胡搞题 注意:一开始你是在图内的,并不是从外面走向图内的,所以你一开始的位置要标记,并且保存的步数是0,dfs函数代表下一步的位置的情况,book保存的是你当前的步数(相对于本次表示的是上一次经过这个位置的步数),循环条件就是你遇到

小胡同的诗 288

HDU 1035 Robot Motion【模拟】

题目传送门;点击打开链接Robot Motion Time Limit: 1000 MSMemory Limit: 65536 KTotal Submit: 268(133 users)Total Accepted: 145(124 users)Rating:Special Judge: NoDescriptionA robot has been programmed to follow the ...

Emiya丶的博客 480

HDU 1035 Robot Motion

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035   简单

M阳光的专栏 666

hdu 1035 Robot Motion

hdu  1035  Robot Motion                             http://acm.hdu.edu.cn/showproblem.php?pid=1035 貌似搜索的模拟 题目大意:一个二维表,每一个点上有一个路标,指向东西南北四个方向。从第一行的第t个点进入,按照路标走,只有两种情况,陷入循环或走出这个图。 题目分析:给出表的规模m和n、t,以及表

slicer的技术交流栈 786

HDU1035——Robot Motion

http://acm.hdu.edu.cn/showproblem.php?pid=1035 这倒题讲的是机器人通过给定的方向标识,判断花多长时间退出或者话多久后进入循环。 当然这道题也是用的深搜,改变的只有坐标就好了,问题是而且vis数组不需要reset,因为要判断是否重新回到一个点——会不会发生循环。 难点:记录走了多少步,我是在vis数组中记录当前是第几步,一举两得。记住有可...

aozhe0658的博客 157
上一篇: POJ 3273 - Monthly Expense(二分)
下一篇: POJ 2139 - Six Degrees of Cowvin Bacon(floyd)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值