热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

codeforces908BNewYearandBuggyBot

(http:www.elijahqi.win20171230codeforces-908-b-new-year-and-buggy-bot)B.NewYearandBu

(http://www.elijahqi.win/2017/12/30/codeforces-908-b-new-year-and-buggy-bot/)
B. New Year and Buggy Bot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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. It’s start position is denoted with the character ‘S’. This position has no obstacle in it. There is also a single exit in the maze. It’s 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.

给定一张图 给定起点终点 再给定操控的过程 但是操控操作方法和他所对应的UP DOWN LEFT RIGHT 并非一一对应 所以我需要暴力枚举 题目中给的3 2 1 0到底哪一个代表向上走 向右走 然后确定了这种方案之后我需要按照题目中给出的操作 来模拟一下这个过程看最终有多少方案可以走到终点


#include
#include
int dx[]={-1,0,1,0},dy[]={0,1,0,-1},n,m,ans,mp[5],len,stx,sty,edx,edy;
char s[55][55],order[55];
inline void gao(){
    int x=stx,y=sty;
    for (int i=1;i<=len;++i){
        x+=dx[mp[order[i]-'0']];y+=dy[mp[order[i]-'0']];
        if (x<1||x>n||y<1||y>m||s[x][y]=='#') return;
        if (x==edx&&y==edy) {++ans;return;}
    }
}
int main(){
// freopen("cfb.in","r",stdin);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i) scanf("%s",s[i]+1);
    for (int i=1;i<=n;++i)
        for (int j=1;j<=m;++j) {
            if (s[i][j]=='S') stx=i,sty=j;if (s[i][j]=='E') edx=i,edy=j; 
        }
    scanf("%s",order+1);len=strlen(order+1);
    for (int i=0;i<4;++i){
        for (int j=0;j<4;++j){
            if (i==j) continue;
            for (int k1=0;k1<4;++k1){
                if (k1==i||k1==j) continue;
                for (int k2=0;k2<4;++k2){
                    if (k2==i||k2==j||k2==k1) continue;
                    mp[i]=0;mp[j]=1;mp[k1]=2;mp[k2]=3;
                    gao();
                }
            }
        }
    }printf("%d\n",ans);
    return 0;
}


推荐阅读
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • c语言\n不换行,c语言printf不换行
    本文目录一览:1、C语言不换行输入2、c语言的 ... [详细]
  • 本文介绍了一种划分和计数油田地块的方法。根据给定的条件,通过遍历和DFS算法,将符合条件的地块标记为不符合条件的地块,并进行计数。同时,还介绍了如何判断点是否在给定范围内的方法。 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • 本文介绍了C函数ispunct()的用法及示例代码。ispunct()函数用于检查传递的字符是否是标点符号,如果是标点符号则返回非零值,否则返回零。示例代码演示了如何使用ispunct()函数来判断字符是否为标点符号。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • 本文介绍了PE文件结构中的导出表的解析方法,包括获取区段头表、遍历查找所在的区段等步骤。通过该方法可以准确地解析PE文件中的导出表信息。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了为什么要使用多进程处理TCP服务端,多进程的好处包括可靠性高和处理大量数据时速度快。然而,多进程不能共享进程空间,因此有一些变量不能共享。文章还提供了使用多进程实现TCP服务端的代码,并对代码进行了详细注释。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
author-avatar
w康d
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有