题意

题目链接

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. webApp开发中的总结

    meta标签:  H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 <meta name="viewport" content="width=device-wid ...

  2. WCF:初识

    结构: using System.ServiceModel; namespace MyServices { [ServiceContract] public interface IHomeServic ...

  3. python互斥锁

    互斥锁 进程之间数据隔离, 但是多个进程可以共享同一块数据,比如共享同一套文件系统,所以访问同一个文件,或同一个打印终端,是没有问题的,而共享带来的是竞争,竞争带来的结果就是错乱,如下 from mu ...

  4. Apache JMeter的基本使用

    安装 安装地址:http://jmeter.apache.org/download_jmeter.cgi 解压后运行jmeter.bat的批处理文件就可以了 JMeter测试脚本编写: 1,创建线程组 ...

  5. 01-02 notepad++安装、配置及使用

    一.安装 按照默认设置,下一步下一步即可. 二.配置 设置-->首选项-->新建

  6. xamarin自定义 application 无法调试

    我们在默认使用application 的时候发现 调试会爆异常 [application] public class DemoApplication:Application { } 根本原因是构造器 ...

  7. JavaScript -- Table

    -----048-Table.html----- <!DOCTYPE html> <html> <head> <meta http-equiv="c ...

  8. JAVA 利用Dom4j实现英语六级词汇查询 含演示地址

    要求 必备知识 基本了解JAVA编程知识,DOM基础. 开发环境 MyEclipse10 演示地址 演示地址     通过前面几天的学习,现在基本掌握了JAVA操作DOM方面的知识,现在来一个小DEM ...

  9. js便签笔记(11)——浏览TOM大叔博客的学习笔记 part1

    1. 前言 这两天看了一下TOM大叔的<深入理解js系列>中的基础部分,根据自己的实际情况,做了读书笔记,记录了部分容易绊脚的问题.写篇文章,供大家分享. 2. 关于HTMLCollect ...

  10. 比特币算法——SHA256算法介绍

    SHA256是安全散列算法SHA(Secure Hash Algorithm)系列算法之一,其摘要长度为256bits,即32个字节,故称SHA256.SHA系列算法是美国国家安全局 (NSA) 设计 ...