题意

题目链接

Sol

接下来我的实现方式和论文里不太一样

然后用bitset优化,上下走分别对应着右移/左移m位,左右走对应着右移/左移1位

我们可以直接预处理出能走的格子和不能走的格子,每次走的时候先全都走过去,再把撞到墙上的补回来即可

#include<bits/stdc++.h>
#define u32 unsigned int
using namespace std;
const int MAXN = 1e5 + 10, SS = 150 * 150 + 150;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, Len, id;
bitset<SS> now, B, can;
char s[151], str[MAXN];
int main() {
N = read(); M = read(); Len = read();
for(int i = 1; i <= N; i++) {
scanf("%s", s + 1);
for(int j = 1; j <= M; j++) {
if(s[j] == '#') B[i * M + j] = 1;
else can[i * M + j] = now[i * M + j] = 1;
if(s[j] == 'E') id = i * M + j;
}
}
scanf("%s", str + 1);
if(now.count() == 1 && now[id] == 1) return puts("0"), 0;
for(int i = 1; i <= Len; i++) {
if(str[i] == 'U') {
now = ((now >> M) & can) | (now & (B << M));
} else if(str[i] == 'D') {
now = ((now << M) & can) | (now & (B >> M));
} else if(str[i] == 'L') {
now = ((now >> 1) & can) | (now & (B << 1));
} else if(str[i] == 'R') {
now = ((now << 1) & can) | (now & (B >> 1));
}
if(now.count() == 1 && now[id] == 1) {
printf("%d\n", i);
return 0;
}
}
puts("-1");
return 0;
}

cf97D. Robot in Basement(模拟 bitset)的更多相关文章

  1. Codeforces.97D.Robot in Basement(bitset 模拟)

    题目链接 (ozr attack) 考虑怎么暴力,就是先在所有非障碍格子上全放上机器人,然后枚举每一步,枚举每个机器人移动这一步,直到所有机器人都在出口位置.复杂度是\(O(nmk)\)的. 怎么优化 ...

  2. CodeForces 97D. Robot in Basement

    time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. hdu 1035 Robot Motion(模拟)

    Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...

  4. poj1573&amp;&amp;hdu1035 Robot Motion(模拟)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接: HDU:pid=1035">http://acm.hd ...

  5. 使用robot封装一个模拟键盘复制粘贴并按下回车的方法

    /** * 复制数据到剪切板并粘贴出来并按下回车 * @param writeMe 需要粘贴的地址 * @throws java.awt.AWTException */ public void use ...

  6. poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】

                                                                                                         ...

  7. POJ1573(Robot Motion)--简单模拟+简单dfs

    题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...

  8. Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)

    C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard inpu ...

  9. POJ 1573 Robot Motion(模拟)

    题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...

随机推荐

  1. vue教程1-07 模板和过滤器

    vue教程1-07 模板和过滤器 一.模板 {{msg}} 数据更新模板变化 {{*msg}} 数据只绑定一次 {{{msg}}} HTML转意输出 <!DOCTYPE html> < ...

  2. 关于oracle RAC心跳线采用直连 还是交换机连接的建议

    关于oracle RAC心跳线的连接方式,各个论坛,包括网上文章的说法是:官方说是不建议直连,建议采用交换机连接的方式!PS:但是,一直没有找到官方文档的出处,有知道的兄弟,烦请评论区提供下地址!!! ...

  3. Python标准库 -- UUID模块(生成唯一标识)

    UUID是什么: UUID: 通用唯一标识符 ( Universally Unique Identifier ),对于所有的UUID它可以保证在空间和时间上的唯一性,也称为GUID,全称为: UUID ...

  4. MVC3学习:利用mvc3+ajax结合MVCPager实现分页

    本例使用表格Users(Uid,UserName,PassWord),数据库访问使用EF first code. public class Users { [Key] public int Uid { ...

  5. java8之lambda表达式(2)-方法引用

    方法引用使用的地方也是在函数式接口,使用方法引用可以使代码更加简单和便捷 在如下代码中 根据List中字符串长度排序的代码可以写成如下: public static void test1_() { L ...

  6. Shell脚本 | 性能测试之启动流量

    安卓应用的流量统计有多种方式,点击「阅读原文」可以看到一篇别人写的文章,关于安卓流量数据的获取,写的挺全的,列举了几种不同方式的优劣.(见文末参考链接) 今天我要分享的是通过脚本一键获取应用的启动流量 ...

  7. Disruptor多个消费者不重复处理生产者发送过来的消息

    1.定义事件事件(Event)就是通过 Disruptor 进行交换的数据类型. package com.ljq.disruptor; import java.io.Serializable; /** ...

  8. logstash-1-安装配置

    centos logstash logstash logstash是什么呢, 他是一个数据管道, JRuby编写的运行在java虚拟机的具有收集, 分析和转发数据流功能的工具 特性: 安装 1), w ...

  9. Flutter踩坑日记:Tab导航栏保持子页面状态

    最近应邀票圈小伙伴躺坑Flutter,项目初步雏形完结.以原来的工具链版本为基础做了Flutter版本,不过后面还是需要优化下项目接入Redux,以及扩展一些Native方法. 这里记录一下在开发过程 ...

  10. linux下tar gz bz2 tgz z等众多压缩文件的压缩与解压方法

    Linux下最常用的打包程序就是tar了,使用tar程序打出来的包我们常称为tar包,tar包文件的命令通常都是以.tar结尾的.生成tar包后,就可以用其它的程序来进 行压缩了,所以首先就来讲讲ta ...