CSUFT 1002 Robot Navigation
1002: Robot Navigation
| Time Limit: 1 Sec | Memory Limit: 128 MB | |
| Submit: 4 | Solved: 2 |
Description
A robot has been sent to explore a remote planet. To specify the path the robot should take, a program is sent each day. The program consists of a sequence of the following commands:
- FORWARD: move forward by one unit.
- TURN LEFT: turn left by 90 degrees. The robot remains at the same location.
- TURN RIGHT: turn right by 90 degrees. The robot remains at the same location.
The robot also has sensor units which allows it to obtain a map of its surrounding area. The map is represented as a grid ofMrows andNcolumns. Each grid point is represented by a coordinate (r,c) wherer = 0is the north edge of the map,r = M - 1is the south edge,c = 0is the west edge, andc = N - 1is the east edge. Some grid points contain hazards (e.g. craters) and the program must avoid these points or risk losing the robot.
Naturally, if the initial location and direction of the robot and its destination position are known, we wish to send the shortest program (one consisting of the fewest commands) to move the robot to its destination (we do not care which direction it faces at the destination). You are more interested in knowing the number of different shortest programs that can move the robot to its destination, because we may need to send different sequences as interplanetary communication is not necessarily reliable. However, the number of shortest programs can be very large, so you are satisfied to compute the number as a remainder under some modulus, knowing that something you learned in classes called the Chinese remainder theorem can be used to compute the final answer.
Input
The input consists of a number of cases. The first line of each case gives three integersM,N, and the modulusm(0 < M, N <= 1000, 0 < m <= 1000000000). The nextMlines containNcharacters each and specify the map. A '.' indicates that the robot can move into that grid point, and a '*' indicates a hazard. The final line gives four integersr1,c1,r2,c2followed by a characterd. The coordinates (r1,c1) specify the initial position of the robot, and (r2,c2) specify the destination. The character d is one of 'N', 'S', 'W', 'E' indicating the initial direction of the robot. It is assumed that the initial position and the destination are not hazards.
The input is terminated whenm = 0.
Output
For each case, print its case number, the modulus, as well as the remainder of the number of different programs when divided by the modulusm. The output of each case should be on a single line, in the format demonstrated below. If there is no program that can move the robot to its destination, output -1 for the number of different programs.
Sample Input
3 3 100
***
.*.
***
1 0 1 2 E
4 4 100
****
*.*.
*.*.
*...
1 1 1 3 N
4 8 100
********
...**...
*......*
********
1 0 1 7 E
0 0 0
Sample Output
Case 1: 100 -1
Case 2: 100 2
Case 3: 100 4
HINT
Source
#include <bits/stdc++.h>
using namespace std; const char* dirs = "NESW";
const int Maxn = ;
const int INF = 0x3f3f3f3f; int R,C;
int mod; char a[Maxn][Maxn]; struct Node
{
int r,c;
int dir;
Node(int r=,int c=,int dir=):r(r),c(c),dir(dir) {}
}; const int dr[] = {-,,,};
const int dc[] = {,,,-}; Node walk(const Node& u,int turn)
{
int dir = u.dir;
if(turn==) dir = (dir - + )%; // zuo zhuan
if(turn==) dir = (dir+ )%; // you zhuan
if(turn==)
return Node(u.r+dr[dir],u.c+dc[dir],dir);
// zhi zou
return Node(u.r,u.c,dir);
} int d[Maxn][Maxn][];
int sum[Maxn][Maxn][]; int dir_id(char c)
{
return strchr(dirs,c)-dirs;
} int r1,c1,r2,c2,dir; bool inside(int r,int c)
{
if(r>=&&r<R&&c>=&&c<C)
return true;
return false;
} int cnt; int bfs()
{
queue<Node> q;
memset(d,-,sizeof(d));
Node u(r1,c1,dir);
d[u.r][u.c][u.dir] = ;
sum[u.r][u.c][u.dir] = ; q.push(u); cnt = ;
while(!q.empty())
{
Node u = q.front();
q.pop();
for(int i=; i<; i++)
{
Node v = walk(u,i);
if(a[v.r][v.c]=='.'&&inside(v.r,v.c)&&d[v.r][v.c][v.dir]<)
{
d[v.r][v.c][v.dir] = d[u.r][u.c][u.dir] + ;
sum[v.r][v.c][v.dir] = sum[u.r][u.c][u.dir];
q.push(v);
}
else if(a[v.r][v.c]=='.'&&inside(v.r,v.c))
{
if(d[v.r][v.c][v.dir]==d[u.r][u.c][u.dir]+)
{
sum[v.r][v.c][v.dir] = (sum[v.r][v.c][v.dir]+sum[u.r][u.c][u.dir])%mod;
}
}
}
} int ans = INF;
for(int i=; i<; i++)
{
if(d[r2][c2][i]!=-)
ans = min(ans,d[r2][c2][i]);
} if(ans==INF)
return -; for(int i=; i<; i++)
{
if(ans==d[r2][c2][i])
{
cnt = (cnt + sum[r2][c2][i])%mod;
}
}
return cnt; } void _bfs()
{
queue<Node> q;
memset(d,-,sizeof(d));
Node u(r1,c1,dir);
d[u.r][u.c][u.dir] = ; q.push(u); vector<int> ans;
cnt = ;
while(!q.empty())
{
Node u = q.front();
q.pop(); if(u.r==r2&&u.c==c2)
{
if(ans.size()!=)
{
if(ans[]!=d[u.r][u.c][u.dir])
return ;
else (cnt++)%mod;
}
else
{
cnt++;
ans.push_back(d[u.r][u.c][u.dir]);
} }
for(int i=; i<; i++)
{
Node v = walk(u,i);
if(a[v.r][v.c]=='.'&&inside(v.r,v.c))
{
d[v.r][v.c][v.dir] = d[u.r][u.c][u.dir] + ;
q.push(v);
}
}
}
} int main()
{ int kase = ;
while(scanf("%d%d%d",&R,&C,&mod),R)
{
memset(d,-,sizeof(d));
for(int i=; i<R; i++)
scanf("%s",a[i]); char str[];
scanf("%d%d%d%d%s",&r1,&c1,&r2,&c2,str); dir = dir_id(str[]); printf("Case %d: %d %d\n",++kase,mod,bfs());
}
return ;
} /**************************************************************
Problem: 1002
User: YinJianZuiShuai
Language: C++
Result: Accepted
Time:284 ms
Memory:34260 kb
****************************************************************/
CSUFT 1002 Robot Navigation的更多相关文章
- HDU 4166 & BNU 32715 Robot Navigation (记忆化bfs)
题意:给一个二维地图,每个点为障碍或者空地,有一个机器人有三种操作:1.向前走:2.左转90度:3.右转90度.现给定起点和终点,问到达终点最短路的条数. 思路:一般的题目只是求最短路的长度,但本题还 ...
- Robot Perception for Indoor Navigation《室内导航中的机器人感知》
Felix Endres 论文下载 Technische Fakult¨ atAlbert-Ludwigs-Universit¨ at Freiburg Betreuer: Prof. Dr. Wol ...
- Simulating a Freight robot in Gazebo
Installation Before installing the simulation environment, make sure your desktop is setup with a st ...
- Simulating a Fetch robot in Gazebo
Installation Before installing the simulation environment, make sure your desktop is setup with a st ...
- 泡泡一分钟:Topomap: Topological Mapping and Navigation Based on Visual SLAM Maps
Topomap: Topological Mapping and Navigation Based on Visual SLAM Maps Fabian Bl¨ochliger, Marius Feh ...
- SLAM学习笔记(3)相关概念
SIFT,即尺度不变特征变换(Scale-invariant feature transform,SIFT),是用于图像处理领域的一种描述子.这种描述具有尺度不变性,可在图像中检测出关键点,是一种局部 ...
- 2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】
2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North ...
- Robotics Tools
https://sites.google.com/site/sunglok/rv_tool/robot Robotics Tools Contents 1 Robotics Tutorials 2 R ...
- semantic segmentation 和instance segmentation
作者:周博磊链接:https://www.zhihu.com/question/51704852/answer/127120264来源:知乎著作权归作者所有,转载请联系作者获得授权. 图1. 这张图清 ...
随机推荐
- JS,CSS,HTML制作网页首页,视频轮播,隐藏点击等等。
在整个项目中,总共写了1000+的代码,可以更加简单优化的.整个主页交互效果能基本,包括轮播,视频,点击变化形状,移入蒙版,瀑布流加载滑动,旋转等等.轮播导航没有完全做完,暂时做了往右无限推动.个人觉 ...
- [转] 多线程 《深入浅出 Java Concurrency》目录
http://ifeve.com/java-concurrency-thread-directory/ synchronized使用的内置锁和ReentrantLock这种显式锁在java6以后性能没 ...
- poj: 1004
简单题 #include <iostream> #include <stdio.h> #include <string.h> #include <stack& ...
- checkbox的相关知识点
1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...
- paper 29 :CV会议+领先研究室+专家+代码网址
做机器视觉和图像处理方面的研究工作,最重要的两个问题:其一是要把握住国际上最前沿的内容:其二是所作工作要具备很高的实用背景.解决第一个问题的办法就是找出这个方向公认最高成就的几个超级专家(看看他们都在 ...
- MyEclipse 死掉,JVM terminated. Exit code=1073807364
刚入手的新成员,刚开始使用myeclipse,是不是会有一大堆的问题,然后没有目标的走,这里有个小技巧,那就是如果做项目出现问题,一定要自己现在网络搜寻答案,网络时代.技术时代走到现在,一定有他的道理 ...
- 解决filezilla中无法显示中文的文件名
设定字符集时选择自定义字符集, 然后输入字符集为 GBK
- js表单提交一种方式
在一个html和php混编的文件中,用到js提交表单的方法: 定义表单id为form1,提交按钮type为submit, var data_info = document.getElementById ...
- 小结 javascript中的类型检测
先吐槽一下博客园的编辑器,太不好用了,一旦粘贴个表格进来就会卡死,每次都要用html编辑器写,不爽! 关于javascript的类型检测,早在实习的时候就应该总结,一直拖到现在,当时因为这个问题还出了 ...
- 华为项目管理10大模板Excel版(可直接套用_非常实用)
项目管理是管理学的一个分支学科 ,对项目管理的定义是:指在项目活动中运用专门的知识.技能.工具和方法,使项目能够在有限资源限定条件下,实现或超过设定的需求和期望的过程.项目管理是对一些与成功地达成一系 ...