题意

题目链接

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. Swift 里 Set (三)Inspecting a Set

    isEmpty /// A Boolean value that indicates whether the set is empty. @inlinable public var isEmpty: ...

  2. POJ 2591

    #include<iostream> #include<stdio.h> #define MAXN 10000001 using namespace std; int a[MA ...

  3. Django F()表达式

    Django F()表达式 一个F()对象代表一个模型字段的值或注释列.使用它可以直接引用模型字段的值并执行数据库操作而不用把它们导入到python的内存中. 相反,Django使用F()对象生成一个 ...

  4. 浅谈Retrofit2+Rxjava2

    近几年,Retrofit犹如燎原之火搬席卷了整个Android界.要是不懂Retrofit,简直不好意思出门...由于近几个项目都没用到Retrofit,无奈只能业余时间自己撸一下,写的不好的地方,还 ...

  5. 移动键盘 滚动input

    window.addEventListener('resize', function () { if(document.activeElement.tagName === 'INPUT'){ docu ...

  6. spring boot 与 自定义interceptor

    前面学习过过滤器, 但是过滤器是针对servlet的, 用在springmvc和spring boot里面, 功能上, 感觉并不是很好用. 那这里来学习一下拦截器. 一. 拦截器的执行顺序 1. 目录 ...

  7. Apache运维中常用功能配置笔记梳理

    Apache 是一款使用量排名第一的 web 服务器,LAMP 中的 A 指的就是它.由于其开源.稳定.安全等特性而被广泛使用.下边记录了使用 Apache 以来经常用到的功能,做此梳理,作为日常运维 ...

  8. Spark2.1.0——剖析spark-shell

    在<Spark2.1.0——运行环境准备>一文介绍了如何准备基本的Spark运行环境,并在<Spark2.1.0——Spark初体验>一文通过在spark-shell中执行wo ...

  9. Python之pymysql的使用

    在python3.x中,可以使用pymysql来MySQL数据库的连接,并实现数据库的各种操作,本次博客主要介绍了pymysql的安装和使用方法. PyMySQL的安装 一..windows上的安装方 ...

  10. Sublime 插件路径