New Year and Buggy Bot
Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.
The robot can only move up, left, right, or down.
When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.
The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.
Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.
Input
The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.
Output
Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.
Example
5 6
.....#
S....#
.#....
.#....
...E..
333300012
1
6 6
......
......
..SE..
......
......
......
01232123212302123021
14
5 3
...
.S.
###
.E.
...
3
0
Note
For the first sample, the only valid mapping is , where D is down, L is left, U is up, R is right.
只要安全到达出口就可以了,可以有多余的指令。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int n,m,dir[][] = {,,,,,-,-,},c = ,visited[],f[],sx,sy;
char mp[][],s[];
int check()
{
int px = sx,py = sy;
for(int i = ;s[i];i ++)
{
px += dir[f[s[i] - '']][],py += dir[f[s[i] - '']][];
if(px < || py < || px >= n || py >= m || mp[px][py] == '#')return ;
if(mp[px][py] == 'E')return ;
}
return ;
}
void dfs(int k)
{
if(k == )
{
if(check())c ++;
return;
}
for(int i = ;i < ;i ++)
{
if(!visited[i])
{
visited[i] = ;
f[k] = i;
dfs(k + );
visited[i] = ;
}
}
}
int main()
{
cin>>n>>m;
for(int i = ;i < n;i ++)
{
for(int j = ;j < m;j ++)
{
cin>>mp[i][j];
if(mp[i][j] == 'S')sx = i,sy = j;
}
}
cin>>s;
dfs();
cout<<c;
}
New Year and Buggy Bot的更多相关文章
- 【Good Bye 2017 B】 New Year and Buggy Bot
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举一下全排列.看看有多少种可以到达终点即可. [代码] #include <bits/stdc++.h> using ...
- Codeforces New Year and Buggy Bot 题解
主要思路:全排列,然后按输入的字符串走并且判断是否撞墙 注:这样不会TLE,全排列最多24种 Code(C++): #include<bits/stdc++.h> using namesp ...
- 冬训 day2
模拟枚举... A - New Year and Buggy Bot(http://codeforces.com/problemset/problem/908/B) 暴力枚举即可,但是直接手动暴力会非 ...
- Good Bye 2017
太菜了啊,一不小心就goodbye rating了 A. New Year and Counting Cards time limit per test 1 second memory limit p ...
- [Codeforces]Good Bye 2017
A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...
- Good Bye 2017 A B C
Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...
- CodeForces Goodbye 2017
传送门 A - New Year and Counting Cards •题意 有n张牌,正面有字母,反面有数字 其中元音字母$a,e,o,i,u$的另一面必须对应$0,2,4,6,8$的偶数 其他字 ...
- cf 908B
B - New Year and Buggy Bot 思路:刚开始看到这个题的时候,一头雾水,也不知道要干什么,后来百度翻译了了一遍,看明白了,不得不说自己的英语太差了,好了,步入正题: 给你n行m列 ...
- 《HelloGitHub》之GitHub Bot
起因 我在github上发起了一个开源项目:<HelloGitHub月刊>,内容是github上收集的好玩,容易上手的开源项目. 目的:因为兴趣是最好的老师,我希望月刊中的内容可以激发读者 ...
随机推荐
- VS 无法调试 IIS
用附加的方式断点无效时. 解决方案: 一.VS设置的 .Net版本 与 IIS应用程序池的版本 不一致. 操作步骤: 1. 在VS-> 项目属性, 配置 自定义Web服务器 , 这里 ...
- jQuery:自学笔记(4)——事件与事件对象
jQuery:自学笔记(4)——事件与事件对象 jQuery中的事件 什么是事件 所谓事件,就是被对象识别的操作,即操作对象队环境变化的感知和反应,例如单击按钮或者敲击键盘上的按键. 所谓事件流,是指 ...
- springboot-数据库
Spring-data-jpa jpa定义了一系列持久化的标准,比如hibernate就实现了这一标准. Springboot 的jpa就是hibernate的整合. 在pom文件中增加配置: < ...
- 【HackerRank】Service Lane
Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light o ...
- SOA 面向服务架构 阅读笔记(二)
SOA并不能保证企业的员工更加轻松,企业的收益更加客观. 6.软件组件 6.1 组件和组件的作用 通过可重用的软件代码-组件,可以构建灵活的软件. 6.2 软件组件又称为应用程序,程序,函数,模 ...
- 跨平台移动开发 手机上使用Iscroll.Js的Banner
二话不说,直接上图,看效果 需要使用Iscroll <script src="content/scripts/iscroll.js"></script> 示 ...
- webstrom上运行node项目配置操作
其实特别简单.... 去webtrom主界面找到下图的按钮,点击 点击之后弹框如下: 点击左上方绿色加号,如下图,点击node.js 点击之后,填写下图中内容: 点击应用,主界面的绿色开始按钮就可以用 ...
- 20145239杜文超《网络攻防》- MSF基础应用
20145239杜文超<网络攻防>- MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit:实现攻击行为的主体,但没有载荷只 ...
- cocos2dx打飞机项目笔记二:BulletLayer类
BulletLayer.h 内容如下 class BulletLayer : public cocos2d::CCLayer { public: CC_SYNTHESIZE(bool, m_IsHer ...
- struts2中常用配置
1.Post提交乱码问题,如果编码采用的是utf-8,那么默认不需要自己处理,因为其默认的常量配置文件就是处理UTF-8的 这个常量值只处理POST提交,get如果乱码还得自己写拦截器处理,一般只要页 ...