快速切题 poj1573
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10708 | Accepted: 5192 |
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)
题意:一个迷宫,机器人从某行最上方进入,跟随每一步到达的迷宫的指示行动,问机器人是否能到达迷宫外(任意一边都可以出),或者会在何时进入圈
应用时:15min
实际用时:51min
原因:读题,x,y用反
- #define ONLINE_JUDGE
- #include<cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- int A,B,sx,sy;
- char maz[101][101];
- int vis[101][101];
- const int dx[4]={0,1,0,-1};
- const int dy[4]={-1,0,1,0};
- int dir(char ch){
- if(ch=='N')return 0;
- else if(ch=='E')return 1;
- else if(ch=='S')return 2;
- return 3;
- }
- void solve(){
- memset(vis,0,sizeof(vis));
- sx--;sy=0;
- int step=0;
- int fx,fy;
- while(!vis[sy][sx]&&sx>=0&&sx<A&&sy>=0&&sy<B&&++step){
- fx=sx;fy=sy;
- vis[sy][sx]=step;
- sx=dx[dir(maz[fy][fx])]+fx;
- sy=dy[dir(maz[fy][fx])]+fy;
- }
- if(sx<0||sy<0||sx>=A||sy>=B)printf("%d step(s) to exit\n",step);
- else {
- printf("%d step(s) before a loop of %d step(s)\n",vis[sy][sx]-1,step+1-vis[sy][sx]);
- }
- }
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("output.txt","w",stdout);
- #endif // ONLINE_JUDGE
- while(scanf("%d%d%d",&B,&A,&sx)==3&&A&&B){
- for(int i=0;i<B;i++)scanf("%s",maz[i]);
- solve();
- }
- return 0;
- }
快速切题 poj1573的更多相关文章
- 快速切题sgu127. Telephone directory
127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 快速切题 sgu123. The sum
123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...
- 快速切题 sgu120. Archipelago 计算几何
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...
- 快速切题 sgu119. Magic Pairs
119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...
- 快速切题 sgu118. Digital Root 秦九韶公式
118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...
- 快速切题 sgu117. Counting 分解质因数
117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...
- 快速切题 sgu116. Index of super-prime bfs+树思想
116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...
- 快速切题 sgu115. Calendar 模拟 难度:0
115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...
随机推荐
- Python3基础 str format 四舍六入五凑偶 保留一位小数
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- C#中dll附加配置文件
DLL-with-configuration-file带配置文件的dll http://www.codeproject.com/Tips/199441/DLL-with-configuration-f ...
- UVA 11806 Cheerleaders (容斥原理
1.题意描述 本题大致意思是讲:给定一个广场,把它分为M行N列的正方形小框.现在给定有K个拉拉队员,每一个拉拉队员需要站在小框内进行表演.但是表演过程中有如下要求: (1)每一个小框只能站立一个拉拉队 ...
- UVa 11729 突击战
https://vjudge.net/problem/UVA-11729 题意:有n个部下,每个部下需要完成一项任务.第i个部下需要你话B分钟交代任务,然后立刻执行J分钟完成任务.安排交代任务顺序并计 ...
- Linux(CentOS 6.5) 下安装MySql 5.7.18 二进制版本粗浅攻略
鉴于Linux和mysql因不同版本,安装方式也不同,所以在阅读本攻略前,请确保各位同学的版本和我的Linux.MySql 版本一致. 如果不一致,只能参考. 我的版本: Linux CentOS 6 ...
- python 时间戳转元组
#!/usr/bin/python # -*- coding: UTF- -*- import time localtime = time.localtime(time.time()) print(& ...
- listener TNS-01189 问题
-- 启动监听,提示已经启动. [oracle@sh ~]$ lsnrctl start LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 0 ...
- TinyXML用法小结2
参考:http://www.cnblogs.com/hgwang/p/5833638.html TinyXML用法小结 1. 介绍 Tinyxml的官方网址:http://www.grinn ...
- [ios][swift]swift中如果做基本类型的转换
在swift中如果做基本类型的转换的?比如Int -> Float(Double)Double -> 保留两位小数String -> IntDouble -> String 有 ...
- 《A_Pancers团队》———团队项目原型设计与开发
一.实验目的与要求 (1)掌握软件原型开发技术: (2)学习使用软件原型开发工具:本实验中使用墨刀 二.实验内容与步骤 任务1:针对实验六团队项目选题,采用适当的原型开发工具设计团队项目原型: 任务2 ...