杭电1035
来源:互联网 发布:js动态创建div容器 编辑:程序博客网 时间:2024/05/17 04:45
这道题很简单,用一个矩阵纪录该机器人是否走过某一个地方,当其走过该处纪录当前步数,接着如果走到一个以前走过的地方,就是循环了,若是走到边界就是走出去了。
#include<iostream>#include<string>using namespace std;int main(){ int row,col,pos; cin>>row>>col>>pos; while(row!=0&&col!=0&&pos!=0){ int line=0; pos=pos-1; int count=0; bool out=false; string *strs=new string[row]; int** matrix=new int*[row]; for(int i=0;i<row;i++){ matrix[i]=new int[col]; } for(int i=0;i<row;i++){ cin>>strs[i]; } for(int i=0;i<row;i++){ for(int j=0;j<col;j++) matrix[i][j]=0; } while(!out){ if(matrix[line][pos]!=0) //已经走过了,陷入循环中 break; matrix[line][pos]=++count; switch (strs[line][pos]){ case 'N':line-=1;break; case 'S':line+=1;break; case 'W':pos-=1; break; case 'E':pos+=1; break; } if(line==-1||pos==-1||line==row||pos==col)//可以出去了 out=true; } if(out){ cout<<count<<" step(s) to exit"<<endl; }else cout<<matrix[line][pos]-1<<" step(s) before a loop of "<<count-matrix[line][pos]+1<<" step(s)"<<endl; cin>>row>>col>>pos; } return 0;}
阅读全文
0 0
- 杭电1035
- 杭电1035 Robot Motion
- 杭电-模拟-1280-1035
- 杭电
- 杭电
- 杭电
- 杭电 hdu 1035 Robot Motion
- 杭电 HDU 1035 Robot Motion
- 杭电 HDU 1035 Robot Motion
- 杭电OJ-1035_Robot Motion
- 杭电oj----1035 Robot Motion
- 杭电 ACM 1035 简单模拟题
- 杭电 1234 和 杭电 2115
- 杭电2056之Rectangles 杭电
- 杭电ACM1061Rightmost Digit
- 杭电2099 7.11
- 杭电ACM 1003
- 杭电 ACM 2016
- Ubuntu内部错误信息及处理
- vue中利用百度地图API显示两点间的距离
- excel sheet合并 宏初学
- MySQL学习笔记
- 支付宝授权登录
- 杭电1035
- 使用Git 一键部署到服务器
- Linux : rc.local 重启不生效
- 解决eclipse编译时报内存不足问题
- Map和List使用区别
- Quartz(二) quartz测试
- 光环国际PMP:看完你就知道什么是瞎忙与高效
- dagger2学习
- hdu 6216 A Cubic number and A Cubic Number