poj 1573 Robot Motion(模拟题)
来源:互联网 发布:信息系统网络建设方案 编辑:程序博客网 时间:2024/05/21 17:33
这一题还是模拟题,在oj出现错误,一直到现在才发现,是条件的判定顺序是错误的,应该判断是不是越界,再判定是不是访问过。~~~~~
传上来有乱码,这是原始代码 http://my.csdn.net/enigma_hao/code/detail/54876,有注释的,但跟跟正确代码有区别的,注释可以参考
#include <iostream>#define MAX 13using namespace std;/*288K0MS*/typedef struct _position{ int x; int y;}position; //function position GetPos(char pa); int main(){ int row,col,enter; while(cin>>row>>col>>enter) { if(row==0&&col==0&&enter==0) break; char a[MAX][MAX]; int c[MAX][MAX]; // for(int i=0;i<row;i++) cin>>a[i]; //????? memset(c,0,sizeof(c)); int x,y;//????????? x=0;y=enter-1; bool f1,f2; f1=f2=true; int counter=0; while(f1&&f2) { if(x<0||y<0||x>=row||y>=col) { f2=false; //??????? break; } if(c[x][y]!=0) { f1=false; //???????? break; } char now=a[x][y]; position p=GetPos(now); counter++; //??? c[x][y]=counter; //??????????????? x+=p.x; y+=p.y; } if(!f2) cout<<counter<<" step(s) to exit"<<endl; else if(!f1) cout<<c[x][y]-1<<" step(s) before a loop of "<<counter-c[x][y]+1<<" step(s)"<<endl; } system("pause"); return 0;} position GetPos(char pa){ position p; switch(pa) { case 'N': p.x=-1;p.y=0; break; case 'W': p.x=0;p.y=-1; break; case 'S': p.x=1;p.y=0; break; case 'E': p.x=0;p.y=1; break; default: break; } return p;}
原始代码:
#include <iostream>#define MAX 13using namespace std; typedef struct _position{ int x; int y;}position; //function position GetPos(char pa); int main(){ int row,col,enter; while(cin>>row>>col>>enter) { if(row==0&&col==0&&enter==0) break; char a[MAX][MAX]; int c[MAX][MAX]; //指的是当前位置第一次被访问,0代表是的没被访问 for(int i=0;i<row;i++) cin>>a[i]; //初始化程序 memset(c,0,sizeof(c)); int x,y;//当前光标所在的位置 x=0;y=enter-1; bool f1,f2; f1=f2=true; int counter=0; while(f1&&f2) { if(c[x][y]!=0) { f1=false; //代表第一种的错误 break; } if(x<0||y<0||x>=row||y>=col) { f2=false; //代表第二种错误 break; } char now=a[x][y]; position p=GetPos(now); counter++; //计数器 c[x][y]=counter; //改变当前的光标的横坐标和纵坐标 x+=p.x; y+=p.y; } if(!f2) cout<<counter<<" step(s) to exit"<<endl; else if(!f1) cout<<c[x][y]-1<<" step(s) before a loop of "<<counter-c[x][y]+1<<" step(s)"<<endl; } system("pause"); return 0;} position GetPos(char pa){ position p; switch(pa) { case 'N': p.x=-1;p.y=0; break; case 'W': p.x=0;p.y=-1; break; case 'S': p.x=1;p.y=0; break; case 'E': p.x=0;p.y=1; break; default: break; } return p;}
- poj 1573 Robot Motion(模拟题)
- POJ 1573 Robot Motion(模拟水题)
- poj 1573 Robot Motion (模拟题)
- POJ 1573 Robot Motion模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573-Robot Motion(模拟)
- poj-1573-Robot Motion--模拟
- POJ 1573 Robot Motion(模拟)
- poj 1573 Robot Motion(模拟)
- poj 1573 Robot Motion 模拟
- poj 1573 Robot Motion 【模拟】【刷题计划】
- POJ 1573 Robot Motion 递归模拟
- POJ 1573:Robot Motion:简单模拟
- POJ 1573 Robot Motion (经典模拟)
- POJ 1573 Robot Motion(模拟)
- HDU 1035 && poj 1573 Robot Motion【模拟】
- OpenGL
- 关于Head First Servlet&Jsp。。
- C++ Primer 有感(函数)
- 我创业失败的血泪史
- 15 Awesome Free JavaScript Charts
- poj 1573 Robot Motion(模拟题)
- Android4.2设置--显示--休眠代码跟踪
- ptags.py
- 调用WTL中的CFileDialog来打开一个文件
- objective-c的categories(分类)
- APP上演魔法:三个杭州小伙做手游吸金千万
- leetcode - Permutations II
- jsonp获取服务器的数据的方式
- 开了个BLOG,却不知道写什么