POJ 1573 Robot Motion 模拟 难度:0
- #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 print(int step){
- for(int s=1;s<step;s++){
- for(int i=0;i<A;i++){
- for(int j=0;j<B;j++){
- if(vis[j][i]==s){
- printf("vis[%d][%d]:%d\n",j,i,vis[j][i]);
- }
- }
- }
- }
- }
- 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;
- }
POJ 1573 Robot Motion 模拟 难度:0的更多相关文章
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
- poj 1573 Robot Motion_模拟
又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
随机推荐
- [转载] 360分布式存储系统Bada的设计和应用
原文: http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=208931479&idx=1&sn=1dc6ea4fa28a ...
- 对sizeof的思考
一.sizeof的特点(与strlen比较) 1.sizeof是运算符,strlen是函数,这意味着编译程序在编译的时候就把sizeof计算过了,所以sizeof(x)可以用来定义数组维数. 例如 i ...
- 学习日记day 10 : JavaScript秋风扫落叶第一期
1:实参形参概念清晰化 注意调用,声明和定义的区别. 调用发过去的都是实参,声明和定义中使用的都是形参. 例子: funcOperate (int a); //这是函数声明:参数都是形参: int ...
- 花神的数论题(数位dp)
规定sum[i] 为i里面含1的个数 ,求从1-N sum[i]的乘积. 数为64位内的,也就是sum[i]<=64的,这样可以dp求出1-N中含k个1的数有多少个,快速幂一下就可以了. 有个地 ...
- XML 解析器
所有现代浏览器都内建了供读取和操作 XML 的 XML 解析器.解析器把 XML 转换为 XML DOM 对象 - 可通过 JavaScript 操作的对象. 解析 XML 文档为DOM对象 方法一: ...
- asp.net 柱形图
在vs中,如果要使用柱形图,我们大多数使用第三方提供的插件,所以必须要引用样式,这里我使用的是Highcharts-4.1.9插件,百度一下就可以下载到. 关键的js代码: <script sr ...
- iOS开发之 Xcode 一个工程 Project 添加多个 target
http://www.360doc.com/content/14/1203/11/19119980_430056974.shtml# 根据项目需求,同一个工程有多个版本,每个版本只有细微的不同.所以, ...
- jQuery动态加载脚本 $.getScript();
jQuery.getScript("/path/to/myscript.js", function(data, status, jqxhr) { /* ...
- 转: 浅谈C/C++中的指针和数组(二)
转自:http://www.cnblogs.com/dolphin0520/archive/2011/11/09/2242419.html 浅谈C/C++中的指针和数组(二) 前面已经讨论了指针和数组 ...
- Windows 调色板
目录 第1章调色板 1 1.1 为什么要使用调色板 1 1.2 使用调色板 2 1.2.1 创建逻辑调色板 2 1.2.2 使用 3 1.2.3 销毁逻辑调色板 4 ...