poj1573Robot Motion

背景:一次ac,但做这种没有中文的题做多了,已经严重让我怀疑我自己了,毕竟英语太烂,读懂题意就要读好久。

思路:主要用两个数组模拟整个path,一个用字符串数组来模拟出整个命令,然后用一个整型数组初始化为0,每次走一步就标记一下,这样就能很快的找到结束条件了。

学习:懂得简化代码,把各种情况相同部分的代码写到一起。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char path[12][12];
void judge(int r,int c,int x,int y)
{
    int path2[12][12],k=2;
    memset(path2,0,sizeof(path2));
    path2[y][x]=1;
    while(1)
    {
        char ch=path[y][x];
        int x1=x,y1=y;
        if(ch=='W') x1=x-1;
        if(ch=='E') x1=x+1;
        if(ch=='N') y1=y-1;
        if(ch=='S') y1=y+1;
        if(x1>=0&&x1<r&&y1>=0&&y1<c)
        {
            if(!path2[y1][x1])
            {
                path2[y1][x1]=k;k++;
                x=x1;y=y1;
            }
            else
            {
                cout<<path2[y1][x1]-1<<" step(s) before a loop of ";
                cout<<path2[y][x]-path2[y1][x1]+1<<" step(s)"<<endl;
                return;
            }
        }
        if(x1<0||y1<0||x1>=r||y1>=c)
        {
            cout<<path2[y][x]<<" step(s) to exit"<<endl;
            return;
        }
    }
}
int main()
{
    int r,c,qishi;
    while(cin>>c>>r>>qishi&&r&&c&&qishi)
    {
        memset(path,'A',sizeof(path));
        for(int i=0;i<c;i++)
            scanf("%s",path[i]);
        judge(r,c,qishi-1,0);
    }
    return 0;
}
时间: 2024-08-02 22:18:36

poj1573Robot Motion的相关文章

Google Tango Java SDK开发:Motion Tracking 运动追踪

Java API Motion Tracking Tutorial运动追踪教程 This page describes how the Java API handles motion tracking. 该页面描述了如何使用Java API处理运动追踪. Lifecycle 生命周期 The normal motion tracking system lifecycle consists of three states: TangoPoseData.POSE_INITIALIZING, Tang

V-rep学习笔记:Reflexxes Motion Library 2

VREP中的simRMLMoveToPosition函数可以将静态物体按照设定的运动规律移动到指定的目标位置/姿态.If your object is dynamically enabled, it will not work (since in that case the position of the object is dictated by the physics engine). In that case, make sure to uncheck the Body is dynami

touches,motion触摸事件响应

//触摸事件响应需要重写方法 1 // 触摸时触发该方法(消息发送) 2 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 3 UITouch *touch = [touches anyObject]; 4 CGPoint point = [touch locationInView:self.rootView.touchView];//locationInView:得到当前点击下在指定视图中

Unity3D 中 Generic 动画导入设置和 Root Motion 之间的关系

2条评论 Unity3D 的 Mecanim 动画系统可以直接复用 3DS MAX 中制作的动画文件中的位移,这个就是通过 applyRootMotion 来达成的,我们只需要在使用 Animator 控制动画播放的同时,设置 Animator 的 applyRootMotion 字段为 True 就 OK 了. 那么怎么来利用这个特性达成我们想要的一些效果呢?这个 applyRootMotion 到底指的是啥呢? ApplyRootMotion,从字面上理解来看,是『应用根节点的运动』,听起来

hdoj 1035 Robot Motion

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7974    Accepted Submission(s): 3685 Problem Description A robot has been programmed to follow the instructions in its path. Instruct

【VR】Leap Motion 官网文档 HandModel(手部模型)

前言: 本系列译文是为迎合Unity VR的热潮与大家的学习需要,推出的针对Unity方向的Leap Motion官方文档中英对照翻译. 本篇为第六篇 <HandModel(手部模型)> ,该类主要用于连接控制器和手部模型,以及处理手臂.肘部.手掌.手指的位置和角度等信息. Handmodel is the base class for all the other hand scripts. If you are creating your own hands and need a custo

POJ 1573 Robot Motion 搜索

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6297    Accepted Submission(s): 2952 Problem Description A robot has been programmed to follow the instructions in its path. Instruc

动效设计必备:元素周期运动表(Periodic Table Motion)

今天分享一个元素周期运动表,这个并不是化学元素,你可以理解为「元素运动规律」,因为这个元素表是由一些常用动效组成,并且每个动效的实现都有一个理论依据,而不是凭空想象出来.动效有弯曲.偏移.流动线.噪波.回旋路径.极坐标.音频波浪.对称旋转.连接.遮罩消除等效果.对到交互设计师,想了解动态设计原理,建议收藏此表. 网站名称:Periodic Table Motion 网站地址:http://foxcodex.html.xdomain.jp/ 进入网站后,我们点击每个动画都有尽介绍! 下面来看看这些

HTC Vive 与Leap Motion 出现位置错误的问题

Leap Motion已经支持VR, 但是官方没有支持HTC Vive的例子. 按照官方的文档, 其实是有问题的: https://developer.leapmotion.com/documentation/unity/unity/Unity_Custom_Rig.html Add the LeapVRTemporalWarping script component to the LeapSpace component you just created. Double check that t