hdu 1035 Robot Motion(dfs)
虽然做出来了,还是很失望的!!!
加油!!!还是慢慢来吧!!!
》》》》》》》》》》》》》》》》》》》》》》》》》》《《《《《《《《《《《《《《《《《《《《《《《《《《《
》》》》《《《《
很简单的一道题,一步步的走,走出矩阵则说明没有环,若走到已经走过的地方,说明有环,按格式输出结果即可!!!
#include<stdio.h>
#include<string.h>
int n,m,temp;
int ans[1010][1010];
char map[1010][1010];
void dfs(int sx,int sy)
{
while(sx>=0&&sx<n&&sy>=0&&sy<m&&map[sx][sy]!='o')
{
if(map[sx][sy]=='S')
{
//
temp++;
map[sx][sy]='o';
ans[sx][sy]=++temp;
sx++;
}
else if(map[sx][sy]=='N')
{
//temp++;
map[sx][sy]='o';
ans[sx][sy]=++temp;
sx--;
}
else if(map[sx][sy]=='E')
{
//temp++;
map[sx][sy]='o';
ans[sx][sy]=++temp;
sy++;
}
else if(map[sx][sy]=='W')
{
//temp++;
map[sx][sy]='o';
ans[sx][sy]=++temp;
sy--;
}
}
if(map[sx][sy]=='o')
printf("%d step(s) before a loop of %d step(s)\n",ans[sx][sy]-1,temp-ans[sx][sy]+1);
else
printf("%d step(s) to exit\n",temp);
}
int main()
{
int k,i;
while(scanf("%d %d %d",&n,&m,&k),n+m+k)
{
memset(ans,0,sizeof(ans));
for(i=0;i<n;i++)
scanf("%s",map[i]);
temp=0;
dfs(0,k-1);
}
return 0;
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035
hdu 1035 Robot Motion(dfs)的更多相关文章
- HDOJ(HDU).1035 Robot Motion (DFS)
HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...
- (step 4.3.5)hdu 1035(Robot Motion——DFS)
题目大意:输入三个整数n,m,k,分别表示在接下来有一个n行m列的地图.一个机器人从第一行的第k列进入.问机器人经过多少步才能出来.如果出现了循环 则输出循环的步数 解题思路:DFS 代码如下(有详细 ...
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
- HDU 1035 Robot Motion(dfs + 模拟)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035 这道题比较简单,但自己一直被卡,原因就是在读入mp这张字符图的时候用了scanf被卡. ...
- 题解报告:hdu 1035 Robot Motion(简单搜索一遍)
Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...
- hdu 1035 Robot Motion(模拟)
Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...
- hdu1035 Robot Motion (DFS)
Robot Motion Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- hdoj 1035 Robot Motion
Robot Motion Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
随机推荐
- Selenium模拟登陆简书
from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.c ...
- .net中session的使用
什么是Session? Session即会话,是指一个用户在一段时间内对某一个站点的一次访问. Session对象在.NET中对应HttpSessionState类,表示"会话状态" ...
- 【筛法求素数】【推导】【组合数】UVALive - 7642 - Prime Distance
题意:n个格子,m个球,让你把球放入某些格子里,使得所有有球的格子之间的距离(abs(i-j))均为素数 ,让你输出方案数. 只占一个格子或者两个格子显然可行. 占有三个格子的情况下,则必须保证其中两 ...
- ElasticSearch学习笔记--1、安装以及运行
Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎,多的我就不细说了. 相关实验环境 Centos:7.3 ElasticSearch:5.6 java:1.8 1. ...
- 升级到php7和安装拓展(mac centos)
Mac升级到php7 使用homebrew安装php7 brew update #更新源 brew search php #查找源中的php,发现有php7.1版本,安装最新的php7.1 brew ...
- 简单DP+暴力 POJ 1050
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45915 Accepted: 24282 Desc ...
- Swift 笔记1
// Playground - noun: a place where people can play import Cocoa var str = "Hello, playground&q ...
- iOS自定义全屏返回与tableView左划删除手势冲突解决
当自定义一个navigationController实现全屏右划返回时, 使用起来是不是很爽, 代码如下: - (void)viewDidLoad { [super viewDidLoad]; UIG ...
- OpenVPN Server端配置文件详细说明(转)
本文将介绍如何配置OpenVPN服务器端的配置文件.在Windows系统中,该配置文件一般叫做server.ovpn:在Linux/BSD系统中,该配置文件一般叫做server.conf.虽然配置文件 ...
- C# WebHelper-CookieHelper,CacheHelper,SessionHelper
常用web操作工具类,记录一下,本文记录的工具类,都要求引用 System.Web 1.CookieHelper /// <summary> /// Cookie工具类 /// </ ...