HDU-1035 ROBOT NOTION

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<stdio.h>
#include<string.h>
const int e[2]= {0,1},n[2]= {-1,0},w[2]= {0,-1},s[2]= {1,0};
int count=0;
int r,c;
char matrix[10][10];
int record[10][10];
int used[10][10];
void dfs(int x,int y);
int main()
{
    int p,i,j;
    while(scanf("%d%d",&r,&c)!=EOF)
    {
        memset(record,0,sizeof(record));
        memset(used,0,sizeof(used));
        count=0;
        if(r<=0||c<=0)break;
        scanf("%d",&p);
        getchar();
        for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {
                scanf("%c",&matrix[i][j]);
            }
            getchar();
        }
        dfs(0,p-1);
    }
    return 0;
}
void dfs(int x,int y)
{
    int x1,y1;
    if(x<0||y<0||x>=r||y>=c||used[x][y]==1)
    {
        if(used[x][y])
            printf("%d step(s) before a loop of %d step(s)\n",record[x][y]-1,count-record[x][y]+1);
        else
            printf("%d step(s) to exit\n",count);
    }
    else
    {
        ++count;
        record[x][y]=count;
        if(matrix[x][y]=='E')
        {
            x1=x+e[0];
            y1=y+e[1];
        }
        else if(matrix[x][y]=='N')
        {
            x1=x+n[0];
            y1=y+n[1];
        }
        else if(matrix[x][y]=='S')
        {
            x1=x+s[0];
            y1=y+s[1];
        }
        else
        {
            x1=x+w[0];
            y1=y+w[1];
        }
        used[x][y]=1;
        dfs(x1,y1);
    }
}

标题基于SpringBoot+Vue的学生交流互助平台研究AI更换标题第1章引言介绍学生交流互助平台的研究背景、意义、现状、方法与创新点。1.1研究背景与意义分析学生交流互助平台在当前教育环境下的需求及其重要性。1.2国内外研究现状综述国内外在学生交流互助平台方面的研究进展与实践应用。1.3研究方法与创新点概述本研究采用的方法论、技术路线及预期的创新成果。第2章相关理论阐述SpringBoot与Vue框架的理论基础及在学生交流互助平台中的应用。2.1SpringBoot框架概述介绍SpringBoot框架的核心思想、特点及优势。2.2Vue框架概述阐述Vue框架的基本原理、组件化开发思想及与前端的交互机制。2.3SpringBoot与Vue的整合应用探讨SpringBoot与Vue在学生交流互助平台中的整合方式及优势。第3章平台需求分析深入分析学生交流互助平台的功能需求、非功能需求及用户体验要求。3.1功能需求分析详细阐述平台的各项功能需求,如用户管理、信息交流、互助学习等。3.2非功能需求分析对平台的性能、安全性、可扩展性等非功能需求进行分析。3.3用户体验要求从用户角度出发,提出平台在易用性、美观性等方面的要求。第4章平台设计与实现具体描述学生交流互助平台的架构设计、功能实现及前后端交互细节。4.1平台架构设计给出平台的整体架构设计,包括前后端分离、微服务架构等思想的应用。4.2功能模块实现详细阐述各个功能模块的实现过程,如用户登录注册、信息发布与查看、在线交流等。4.3前后端交互细节介绍前后端数据交互的方式、接口设计及数据传输过程中的安全问题。第5章平台测试与优化对平台进行全面的测试,发现并解决潜在问题,同时进行优化以提高性能。5.1测试环境与方案介绍测试环境的搭建及所采用的测试方案,包括单元测试、集成测试等。5.2测试结果分析对测试结果进行详细分析,找出问题的根源并
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值