poj 1573 Robot Motion_模拟
又是被自己的方向搞混了
题意:走出去和遇到之前走过的就输出。
#include <cstdlib>
#include <iostream>
#include<cstdio>
using namespace std;
#define N 110
int map[N][N],visit[N][N],n,m,flag;//n为x轴 m为y轴
int dir[][2]={{0,1},{1,0},{0,-1},{-1,0}};//e,s,w,n
int setdire(char s){
switch(s){
case 'E':return 0;
case 'S':return 1;
case 'W':return 2;
case 'N':return 3;
}
}
void dfs(int x,int y,int num){
int i,j,tx,ty;
if(flag!=1)
return;
tx=x+dir[map[x][y]][0];
ty=y+dir[map[x][y]][1];
if(tx>=0&&tx<n&&ty>=0&&ty<m){
if(visit[tx][ty]){
printf("%d step(s) before a loop of %d step(s)\n",visit[tx][ty]-1,num-visit[tx][ty]+1);
flag=0;
}
else{
visit[x][y]=num;
dfs(tx,ty,num+1);
} }
else{
printf("%d step(s) to exit\n",num);
flag=0;
}
}
int main(int argc, char *argv[])
{
int i,j,x;
char str[N];
while(scanf("%d%d%d",&n,&m,&x)&&(n||m||x)){
for(i=0;i<n;i++){
scanf("%s",str);
for(j=0;j<m;j++){
map[i][j]=setdire(str[j]);
}
}
memset(visit,0,sizeof(visit));
flag=1;
dfs(0,x-1,1);
}
system("PAUSE");
return EXIT_SUCCESS;
}
poj 1573 Robot Motion_模拟的更多相关文章
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- 模拟 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(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作
AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- POJ 1573:Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11324 Accepted: 5512 Des ...
随机推荐
- 学DSP(二):目标芯片28335,GO!
28335开发板有了,之前没有用过TI的片子,还是先看看这个东西是啥东西. 进入28335的中文网页: http://www.ti.com.cn/product/cn/tms320f28335 ...
- spring-boot+nginx+tomcat+ssl配置笔记
如果你的tomcat应用需要采用ssl来加强安全性,一种做法是把tomcat配置为支持ssl,另一种做法是用nginx反向代理tomcat,然后把nginx配置为https访问,并且nginx与tom ...
- 理解最短路径——迪杰斯特拉(dijkstra)算法
原址地址:http://ibupu.link/?id=29 1. 迪杰斯特拉算法简介 迪杰斯特拉(dijkstra)算法是典型的用来解决最短路径的算法,也是很多教程中的范例,由荷兰计算机科 ...
- PHP Database ODBC 之 ODBC
ODBC 是一种应用程序编程接口(Application Programming Interface,API),使我们有能力连接到某个数据源(比如一个 MS Access 数据库). 创建 ODBC ...
- python 性能优化
1.优化循环 循环之外能做的事不要放在循环内,比如下面的优化可以快一倍 2.使用join合并迭代器中的字符串 join对于累加的方式,有大约5倍的提升 3.使用if is 使用if is True比i ...
- IOS7 UITableView一行滑动删除后 被删除行的下一行的点击事件将被忽略解决办法
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSI ...
- IOS 快速排序法
- (NSMutableArray *)QuickSort:(NSMutableArray *)list StartIndex:(NSInteger)startIndex EndIndex:(NSIn ...
- 怎样使用jetty
一直都听说jetty跟Tomcat一样,是一个web容器.之前做项目的时候,也使用过jetty,只是当时jetty是作为一个插件,跟maven集成使用的.那个时候,因为是第一次使用jetty,感觉je ...
- .Net+MySQL
网上很少用.Net+MySQL的组合的,所以资料比较少,发现一个赶紧分享给大家. 通常数据库连接字符串为:Database=dbname;Data Source=192.168.1.1;Port=33 ...
- Android应用开发中webview上传文件的几种思路
1. 常规方法,重写WebChromeClient 的 openFileChooser 方法 private class MyWebChromeClient extends WebChromeClie ...