poj1573 模拟
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 11270 | Accepted: 5487 |
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
Output
Sample Input
3 6 5
NEESWE
WWWESS
SNWWWW
4 5 1
SESWE
EESNW
NWEEN
EWSEN
0 0 0
Sample Output
10 step(s) to exit
3 step(s) before a loop of 8 step(s) 没什么可说的,做不出来可以考虑退出ACM了
#include<stdio.h>
#include<string.h>
char map[100][100];
int vis[100][100];
int flag;
int x,y,h;
void dfs(int tx,int ty){
if(flag==1)
return;
if(map[tx][ty]=='N')
tx-=1;
else if(map[tx][ty]=='S')
tx+=1;
else if(map[tx][ty]=='W')
ty-=1;
else if(map[tx][ty]=='E')
ty+=1;
if(tx<1||tx>x||ty<1||ty>y)
return;
if(vis[tx][ty]==0){
vis[tx][ty]=1;
dfs(tx,ty);
}
else if(vis[tx][ty]==1){
vis[tx][ty]=2;
dfs(tx,ty);
}
else {
flag=1;
return;
}
}
int main(){
while(scanf("%d%d%d",&x,&y,&h)!=EOF){
if(x==0&&y==0&&h==0)
break;
memset(vis,0,sizeof(vis));
memset(map,0,sizeof(map));
getchar();
for(int i=1;i<=x;i++)
gets(map[i]+1);
int tx=1,ty=h;
flag=0;
vis[tx][ty]=1;
dfs(tx,ty);
int sum1=0,sum2=0;
for(int i=1;i<=x;i++){
for(int j=1;j<=y;j++){
if(vis[i][j]==1)
sum1++;
else if(vis[i][j]==2)
sum2++;
}
}
if(sum2==0)
printf("%d step(s) to exit\n",sum1);
else
printf("%d step(s) before a loop of %d step(s)\n",sum1,sum2);
}
return 0;
}
poj1573 模拟的更多相关文章
- poj1573模拟
Robot Motion Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java ...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- poj1573&&hdu1035 Robot Motion(模拟)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接: HDU:pid=1035">http://acm.hd ...
- POJ-1573 Robot Motion模拟
题目链接: https://vjudge.net/problem/POJ-1573 题目大意: 有一个N*M的区域,机器人从第一行的第几列进入,该区域全部由'N' , 'S' , 'W' , 'E' ...
- POJ1573 Robot Motion(模拟)
题目链接. 分析: 很简单的一道题, #include <iostream> #include <cstring> #include <cstdio> #inclu ...
- App开发:模拟服务器数据接口 - MockApi
为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- Python 爬虫模拟登陆知乎
在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...
- HTML 事件(四) 模拟事件操作
本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4. ...
随机推荐
- js中基本操作
1.操作标签值 <!DOCTYPE html> <html> <meta charset="utf-8"> <meta http-equi ...
- Symfony启动过程详细学习
想了解symfony的启动过程,必须从启动文件(这里就以开发者模式)开始. <?php /* * web/app_dev.php */ $loader = require_once __DIR_ ...
- QQ面向对象设计
通讯项目--仿QQ聊天程序 详细设计说明书 一.引言 此项目为验证Jav ...
- android学习——error opening trace file: No such file or directory (2)
1.疑惑: 程序运行起来的时候日志总是显示下面这个错误,但是不影响程序的正常进行,我是用真机来测试的,android4.4.4(API17). 02-11 14:55:03.629 15525-155 ...
- mysql-5.7.9-winx64 MySQL服务无法启动,服务没有报告任何错误的解决办法
问题背景 最新解压版本的mysql 解压安装的时候报错 D:\mysql-5.7.9-winx64\bin>net start mysql MySQL 服务正在启动 . MySQL 服务无法启动 ...
- card-test
<!DOCTYPE html><html> <head> <title>test</title> <style type=" ...
- NServiceBus 结合 RabbitMQ 使用
参考官方教程: Step by Step Guide 新建4个项目: A Console Application named Client A Console Application named Se ...
- 重写UIPageControl实现自定义按钮
有时候UIPageControl需要用到白色的背景, 那么会导致上面的点按钮看不见或不清楚,我们可以通过继承该类重写函数来更换点按钮的图片现实.实现思路如下.新建类继承UIPageControl : ...
- bzoj 3437 斜率优化DP
写题解之前首先要感谢妹子. 比较容易的斜率DP,设sum[i]=Σb[j],sum_[i]=Σb[j]*j,w[i]为第i个建立,前i个的代价. 那么就可以转移了. /**************** ...
- hdu 1008 Elevator
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description The hig ...