POJ 1573
#include<iostream>
#include<stdio.h>
#define MAXN 15
using namespace std; char _m[MAXN][MAXN];
bool mark[MAXN][MAXN];
int record[MAXN][MAXN]; int r;
int c;
void dfs(int i,int j);
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int j;
int place;
while(cin>>r>>c>>place)
{
if(!r && !c && !place)
break;
-- place;
memset(mark,false,sizeof(mark));
// memset(record,0,sizeof(record));
for(i = ; i < r; ++ i)
{
for(j = ; j < c; ++ j)
{
record[i][j] = ;
}
}
for(i = ; i < r; ++ i)
{
for(j = ; j < c; ++ j)
{
cin>>_m[i][j];
}
}
record[][place] = ;
mark[][place] = true;
dfs(,place);
// for(i = 0; i < r; ++ i)
// {
// for(j = 0; j < c; ++ j)
// {
// cout<<record[i][j]<<" ";
// }
// cout<<endl;
// }
}
}
void fun_1(int num);
void fun_2(int num,int num_1);
void dfs(int i,int j)
{
int tem1;
int tem2;
if(_m[i][j] == 'E')
{
if(j + < c)
{
if(!mark[i][j+])
{
mark[i][j+] = true;
record[i][j+] += record[i][j];
dfs(i,j+);
return ;
}
else
{
fun_2(record[i][j+]-,record[i][j]-record[i][j+]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}/////////////////////// if(_m[i][j] == 'S')
{
if(i + < r)
{
if(!mark[i+][j])
{
mark[i+][j] = true;
record[i+][j] += record[i][j];
dfs(i+,j);
return ;
}
else
{
fun_2(record[i+][j]-,record[i][j]-record[i+][j]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}////////////////////////////// if(_m[i][j] == 'W')
{
if(j - >= )
{
if(!mark[i][j-])
{
mark[i][j-] = true;
record[i][j-] += record[i][j];
dfs(i,j-);
return ;
}
else
{
fun_2(record[i][j-]-,record[i][j]-record[i][j-]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}/////////////////////////////////////////// if(_m[i][j] == 'N')
{
if(i - >= )
{
if(!mark[i-][j])
{
mark[i-][j] = true;
record[i-][j] += record[i][j];
dfs(i-,j);
return;
}
else
{
fun_2(record[i-][j]-,record[i][j]-record[i-][j]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}
} void fun_1(int num)
{
cout<<num;
// if(num != 1)
cout<<" step(s) to exit"<<endl;
// else
// cout<<" step to exit"<<endl;
} void fun_2(int num,int num_1)
{
cout<<num;
// if(num != 1)
cout<<" step(s) before a loop of ";
// else
// cout<<" step before a loop of ";
cout<<num_1;
// if(num_1 != 1)
cout<<" step(s)"<<endl;
// else
// cout<<" step"<<endl;
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 1573的更多相关文章
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- POJ 1573 (13.10.11)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- poj 1573 Robot Motion_模拟
又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- Robot Motion - poj 1573
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11269 Accepted: 5486 Description A ...
随机推荐
- shelll函数求两个输入数字之和
#!/bin/bash #This is a test of the addition of the program! function AddFun { read -p "Enter a ...
- kettle日志记录
环境描述: 现在一个项目有很多个作业,需要知道每次跑批后哪些ktr跑成功,哪些失败了 问题解决: 下面是一个具体的操作流程 首先建立数据库表 CREATE TABLE test_1(id INT,NA ...
- 生产库MySQL配置文件my.cnf详解
OS:CentOS6.3 DB:5.6.16 [client] #客户端port = 3306 #数据库端口3306socket = /my/log/mysql.sock #MySQL套接字,多实例下 ...
- Effiective C++ (一)
最近在看Effective C++ ,同时将总结一下里边的重要知识点: ########################## module 1 #################### ...
- poj 2312 Battle City
题目连接 http://poj.org/problem?id=1840 Battle City Description Many of us had played the game "Bat ...
- 28335timer
/*****************************************************************************Copyright: 2014,TkaiFi ...
- 20145129 《Java程序设计》第1周学习总结
20145129 <Java程序设计>第1周学习总结 教材学习内容总结 在第一章学习后初步了解了Java历史及发展,以及JCP,JSR,JVM的相关知识了解.JCP是一个开放性国际组织,由 ...
- CPU大小端判断
两种方式:1.通过指针 2.通过联合体,联合体里面的数据都是按顺序存储的,而且不论联合体里面有多少数据类型,联合体长度是最长的数据类型的长度.不论初始化多少联合体里面的数据,有效的是最 ...
- android 开发 socket发送会有部分乱码,串码,伴随着数据接收不完整
场景: 客户端A.B,A向B发送json字符串后紧接着发送文件,B接收到文件后才返回消息. 环境:android.使用的是原始的write 和read (若使用的是writeUTF不会出现此问题.)需 ...
- 不同系统平台下Java默认的安装路径
下面以Oracle的JDK7update 51为例: • 32-bit JDK on Windows: C:\Program Files (x86)\Java\jdk1.7.0_51 • 64-bit ...