cf97D. Robot in Basement(模拟 bitset)
题意

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)的更多相关文章
- Codeforces.97D.Robot in Basement(bitset 模拟)
题目链接 (ozr attack) 考虑怎么暴力,就是先在所有非障碍格子上全放上机器人,然后枚举每一步,枚举每个机器人移动这一步,直到所有机器人都在出口位置.复杂度是\(O(nmk)\)的. 怎么优化 ...
- CodeForces 97D. Robot in Basement
time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...
- hdu 1035 Robot Motion(模拟)
Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...
- poj1573&&hdu1035 Robot Motion(模拟)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接: HDU:pid=1035">http://acm.hd ...
- 使用robot封装一个模拟键盘复制粘贴并按下回车的方法
/** * 复制数据到剪切板并粘贴出来并按下回车 * @param writeMe 需要粘贴的地址 * @throws java.awt.AWTException */ public void use ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)
C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard inpu ...
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
随机推荐
- Python staticmethod classmethod 普通方法 类变量 实例变量 cls self 概念与区别
类变量 1.需要在一个类的各个对象间交互,即需要一个数据对象为整个类而非某个对象服务. 2.同时又力求不破坏类的封装性,即要求此成员隐藏在类的内部,对外不可见. 3.有独立的存储区,属于整个类. ...
- POJ 2470
#include<iostream> #include<stdio.h> #include<vector> using namespace std; int mai ...
- Java java.lang.ExceptionInInitializerError 错误解决方案
引起 java.lang.ExceptionInInitializerError 错误的原因是:在类的初始化时,出错.也就是说,在加载类时,执行static的属性.方法块时,出错了. 比如 publi ...
- 【转载】win7搜索文件怎么搜索文件名中带圆括号的文件
System.FileName:~=“(” 这样就行. 括号上加个引号 ~= 是包含的意思, ~< 是以什么为开头, = 是以什么为名, ~! 是不包含 来自: http://www.lao8. ...
- 课程一(Neural Networks and Deep Learning),第三周(Shallow neural networks)—— 0、学习目标
Learn to build a neural network with one hidden layer, using forward propagation and backpropagation ...
- IIS:IIS 8.5下设置404错误页
IIS版本:IIS 8.5 问题描述 搭建一个测试网站,总共就2个页面(index.php和404.php),默认首页为:index.php 当访问index.php和404.php的时候,IIS服务 ...
- poj1330-----------关于公共祖先的问题
关于公共祖先的问题分类: 这类问题有多种解法和类型,根据题目给出的信息去判断使用哪一种 1.给你树,只支持从父亲找儿子,不支持儿子找父亲,最后要求最近公共祖先,使用dfs或者分治 2.支持儿子找父亲, ...
- 高可用Hadoop平台-集成Hive HAProxy
1.概述 这篇博客是接着<高可用Hadoop平台>系列讲,本篇博客是为后面用 Hive 来做数据统计做准备的,介绍如何在 Hadoop HA 平台下集成高可用的 Hive 工具,下面我打算 ...
- Linux宝塔软件安装
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install.sh && ...
- Redis 3.2.4集群实战
一.Redis Cluster集群设计Redis集群搭建的方式有多种,例如使用zookeeper等,但从redis3.0之后版本支持Redis-Cluster集群,Redis-Cluster采用无中心 ...