poj1573
题意:给出一个矩形,N,E,S,W分别代表进行移动的方向,如果走出矩形网格则输出经过的网格数,如果在矩形网格内循环,则输出没进入循环之前所走过的网格数和循环所经过的网格数;
思路:创建两个数组,一个字符数组存每个网格中所要进行的操作,另一个整型数组代表状态,0代表没走过,1代表走过了,然后模拟;
再提醒一点,建立的字符和整型数组要和题目中建里的一模一样,因为这个我又WA了一发、
#include<iostream>
#include<cstring>
using namespace std;
const int qq=15;
int gid[qq][qq];char s[qq][qq];
int main()
{
int n,m,k;
while(cin >> n >> m >> k)
{
cin.get();
if(n==0&&m==0&&k==0) break;
memset(gid,0,sizeof(gid));
for(int i=0;i<=m+1;++i){
gid[0][i]=1;gid[n+1][i]=1; //外围标记
}
for(int i=0;i<=n+1;++i){ //外围标记
gid[i][0]=1;gid[i][m+1]=1;
}
for(int j,i=1;i<=n;++i){
for(j=1;j<=m;++j)
s[i][j]=cin.get();
cin.get();
}
int x,y;x=k;y=1;int tot=0;
while(!gid[y][x]){
while(!gid[y][x]&&s[y][x]=='N'){
gid[y][x]=1;y-=1;++tot;
}
while(!gid[y][x]&&s[y][x]=='E'){
gid[y][x]=1;x+=1;++tot;
}
while(!gid[y][x]&&s[y][x]=='S'){
gid[y][x]=1;y+=1;++tot;
}
while(!gid[y][x]&&s[y][x]=='W'){
gid[y][x]=1;x-=1;++tot;
}
}
if(x<1||y<1||x>m||y>n) cout << tot << " step(s) to exit\n";
else{
int count=0;
while(gid[y][x]){ //计算循环所经过的网格数 此时1,0的意义互换
while(gid[y][x]&&s[y][x]=='N'){
gid[y][x]=0;y-=1;++count;
}
while(gid[y][x]&&s[y][x]=='E'){
gid[y][x]=0;x+=1;++count;
}
while(gid[y][x]&&s[y][x]=='S'){
gid[y][x]=0;y+=1;++count;
}
while(gid[y][x]&&s[y][x]=='W'){
gid[y][x]=0;x-=1;++count;
}
}
cout << tot-count << " step(s) before a loop of " << count << " step(s)\n";
}
}
}
poj1573的更多相关文章
- POJ-1573 Robot Motion模拟
题目链接: https://vjudge.net/problem/POJ-1573 题目大意: 有一个N*M的区域,机器人从第一行的第几列进入,该区域全部由'N' , 'S' , 'W' , 'E' ...
- poj1573 Robot Motion(DFS)
题目链接 http://poj.org/problem?id=1573 题意 一个机器人在给定的迷宫中行走,在迷宫中的特定位置只能按照特定的方向行走,有两种情况:①机器人按照方向序列走出迷宫,这时输出 ...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- poj1573 模拟
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11270 Accepted: 5487 Des ...
- POJ1573——Robot Motion
Robot Motion Description A robot has been programmed to follow the instructions in its path. Instruc ...
- POJ1573 Robot Motion(模拟)
题目链接. 分析: 很简单的一道题, #include <iostream> #include <cstring> #include <cstdio> #inclu ...
- poj1573&&hdu1035 Robot Motion(模拟)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接: HDU:pid=1035">http://acm.hd ...
- poj1573模拟
Robot Motion Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java ...
- 快速切题 poj1573
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10708 Accepted: 5192 Des ...
随机推荐
- perfcurve.m
function [X,Y,T,auc,optrocpt,subY,subYnames] = ... perfcurve(labels,scores,posClass,varargin) %PERFC ...
- python-null
很早之前,遇到过一个面试官问的python中有没有null,当时有点紧张,想成了None,就脱口而出是有的.今天遇到了none问题,所以就正好说一下. python中是没有NULL的. Python中 ...
- 实现一个vue的图片预览插件
vue-image-swipe 基于photoswipe实现的vue图片预览组件 安装 1 第一步 npm install vue-image-swipe -D 2 第二步 vue 入口文件引入 im ...
- [case49]聊聊flink的checkpoint配置
序 本文主要研究下flink的checkpoint配置 实例 StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecut ...
- ORACLE 所有 表 记录 条数
SELECT TABLE_NAME,TO_NUMBER(EXTRACTVALUE(XMLTYPE(DBMS_XMLGEN.GETXML('SELECT COUNT(*) CNT FROM '||TAB ...
- JSP Web第三章整理复习 开发环境搭建
P86 WEB工作原理 用户使用浏览器通过HTTP协议请求服务器上的Web资源,服务器接收到该请求后,读取请求的URI所标识的资源,加上其他资源发送给客户端的浏览器,浏览器解析响应中的HTML数据, ...
- Leetcode705.Design HashSet设置哈希集合
不使用任何内建的哈希表库设计一个哈希集合 具体地说,你的设计应该包含以下的功能 add(value):向哈希集合中插入一个值. contains(value) :返回哈希集合中是否存在这个值. rem ...
- OSGi Capabilities
OSGi bundle的Capability就是这个bundle所具有的能力. 就像淘宝上的每个店铺一样,它会说明自己都卖哪些东西,也就是Provide-Capability 我们这些剁手党就会根据自 ...
- 【Leetcode】两数之和,三数之和,四数之和
两数之和 题目 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这 ...
- app被Rejected 的各种原因翻译。这个绝对有用
1. Terms and conditions(法律与条款) 1.1 As a developer of applications for the App Store you are bound b ...