New Year and Buggy Bot (暴力模拟,枚举)

9人阅读 评论(0) 收藏 举报
分类:

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.

Examples
Input
5 6
.....#
S....#
.#....
.#....
...E..
333300012
Output
1
Input
6 6
......
......
..SE..
......
......
......
01232123212302123021
Output
14
Input
5 3
...
.S.
###
.E.
...
3
Output
0
Note

For the first sample, the only valid mapping is , where D is down, L is left, U is up, R is right.

题意:给出一幅二维地图,S表示起点,E表示终点,#表示墙壁,不可走,‘ 。’表示空地,可以走接下来给一个只含有0123的字符串,分别代表上下左右方向的一种,求一共有几种匹配关系可以从S走到E思路:枚举方向的匹配关系,求能走到终点的数量,共A(4,4)种情况,开始没想到如何做,看了博客豁然大悟,真是一波骚操作~~~代码:
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
	int x,y;
}S,E;
char mp[55][55];
string str;
int n,m;
int Next[4]={0,1,2,3};
void Getmap(){
	for(int i=0;i<n;i++){
		cin>>mp[i];
		for(int j=0;j<m;j++){
			if(mp[i][j]=='S'){
				S.x=i;
				S.y=j;
			}
			if(mp[i][j]=='E'){
				E.x=i;
				E.y=j;
			}
		}
	}
}
int solve(){
	int x=S.x,y=S.y;
	for(int i=0;i<str.size();i++){
		int d=str[i]-'0';
		for(int j=0;j<4;j++){
			if(d==Next[j]){
				if(j==0) x++;
				if(j==1) x--;
				if(j==2) y++;
				if(j==3) y--;
			}
			if(x>=n||x<0||y>=m||y<0) return 0;
			else if(mp[x][y]=='#') return 0;
			else if(mp[x][y]=='E') return 1;
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	Getmap();
	cin>>str;
	int ans=0;
	do{
		ans+=solve();
	}while(next_permutation(Next,Next+4));
	cout<<ans<<endl;
	return 0;
}


查看评论

codeforces 908 B New Year and Buggy Bot

(http://www.elijahqi.win/2017/12/30/codeforces-908-b-new-year-and-buggy-bot/) B. New Year and Buggy...
  • elijahqi
  • elijahqi
  • 2017-12-30 16:29:34
  • 169

CodeForces - 908B New Year and Buggy Bot (DFS)

Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are ...
  • UncleJokerly
  • UncleJokerly
  • 2018-01-02 19:42:19
  • 284

codeforces。 goodbye 2017。 B. New Year and Buggy Bot

B. New Year and Buggy Bot time limit per test 1 second memory limit per test 256 megabyt...
  • zzcblogs
  • zzcblogs
  • 2017-12-30 10:21:35
  • 560

New Year and Buggy Bot

New Year and Buggy Bot Bob programmed a robot to navigate through a 2d maze. The maze ha...
  • codeswarrior
  • codeswarrior
  • 2018-01-26 10:58:00
  • 74

cf 908B. New Year and Buggy Bot[暴力+思维]

B. New Year and Buggy Bot time limit per test 1 second memory limit per test 256 megabytes inp...
  • Haipai1998
  • Haipai1998
  • 2018-02-02 15:48:27
  • 40

Codeforces Good Bye 2017 B - New Year and Buggy Bot

简单枚举情况。对于每一种可能的映射都尝试一遍,如果机器人“撞墙”了,则失败,如果在操作集消耗完之前走到终点,则成功。#include #include char maze[55][55],ope[...
  • Myriad_Dreamin
  • Myriad_Dreamin
  • 2017-12-30 12:50:10
  • 193

908B New Year and Buggy Bot

题意 : 0-3代表四个方向,一共24种映射情况,求一共有几种可以从S到达E 然后有一个神奇的函数,next_permutation(a,a+n); 返回值是bool类型,表示比a序列的下一个序列。...
  • ywq4321
  • ywq4321
  • 2018-01-01 11:31:33
  • 28

B. New Year and Buggy Bot

time limit per test 1 second memory limit per test 256 megabytes input standard input ...
  • jj12345jj198999
  • jj12345jj198999
  • 2018-01-15 22:12:53
  • 147

CodeForces - 908B New Year and Buggy Bot

B. New Year and Buggy Bot time limit per test 1 second memory limit per test 256 megabyt...
  • Lngxling
  • Lngxling
  • 2018-02-05 20:52:01
  • 15

Good Bye 2017-B. New Year and Buggy Bot

B. New Year and Buggy Bot time limit per test 1 second memory limit per test 256 megabyt...
  • qq_34531807
  • qq_34531807
  • 2018-01-01 10:14:45
  • 208
    人生哲言
    当能力不足以支持野心时,静下来敲敲代码。
    个人资料
    持之以恒
    等级:
    访问量: 2万+
    积分: 4194
    排名: 9307
    博客专栏
    最新评论