B. Testing Robots

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://www.codeforces.com/contest/606/problem/B

Description

The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same.

After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code.

Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it.

The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up.

Input

The first line of the input contains four integers xyx0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right.

The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'.

Output

Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.

Sample Input

3 4 2 2
UURDRDRL

Sample Output

1 1 0 1 1 1 1 0 6

HINT

题意

题意是给一个x*y的棋盘以及机器人的初始位置,给一个操作序列,对每个k,求有多少个地雷的位置使得走了机器人恰好k步的时候会炸掉(可以是因为操作序列结束也可以是因为踩到地雷),注意到假如走了k步之后的格子在之前已经被访问过,那么机器人即使要炸也会在之前就炸掉,那么对于k=0,1,2,...,len,如果机器人当前所在位置之前未被访问过,输出1,否则输出0,对于k=len+1,记前len个答案之和为tot,输出x*y-tot

题解:

读懂就能AC,前提是你能读懂。。。

代码:

#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
#define maxn 1000110
int vis[][];
int ans[maxn];
string s;
int dx[]={-,,,};
int dy[]={,,-,};
int n,m,x,y;
int check(char c)
{
if(c=='U')return ;
if(c=='R')return ;
if(c=='L')return ;
if(c=='D')return ;
}
int check2(int xx,int yy)
{
if(xx>n||xx<)return ;
if(yy>m||yy<)return ;
return ;
}
int flag = ;
int main()
{
cin>>n>>m>>x>>y;
cin>>s;
vis[x][y]=;
ans[]=;
for(int i=;i<s.size()-;i++)
{
int xx = dx[check(s[i])];
int yy = dy[check(s[i])]; if(check2(x+xx,y+yy))
{
x = x+xx;
y = y+yy;
}
if(vis[x][y])
ans[i+]=;
else
{
ans[i+]=;
vis[x][y]=;
flag++;
}
//cout<<xx<<" "<<yy<<endl;
//cout<<x<<" "<<y<<endl;
}
for(int i=;i<s.size();i++)
printf("%d ",ans[i]);
printf("%d\n",n*m-flag);
}

Codeforces Round #335 (Div. 2) B. Testing Robots 水题的更多相关文章

  1. Codeforces Round #335 (Div. 2)B. Testing Robots解题报告

                                                                                               B. Testin ...

  2. Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)

    B. Testing Robots time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  4. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  5. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  6. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  7. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  8. Codeforces Round #357 (Div. 2) B. Economy Game 水题

    B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...

  9. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

随机推荐

  1. XposedNoRebootModuleSample 不需要频繁重启调试的Xposed 模块源码例子

    XposedNoRebootModuleSample(不需要频繁重启调试的Xposed 模块源码例子) Xposed Module Sample No Need To Reboot When Debu ...

  2. CRF模型

    CRF的全称是Conditional Random Fields,由CMU教授John Lafferty 提出,原文标题:Conditional R andom Fields: Probabilist ...

  3. UML的类图关系分为: 关联、聚合/组合、依赖、泛化(继承)

    UML的类图关系分为: 关联.聚合/组合.依赖.泛化(继承).而其中关联又分为双向关联.单向关联.自身关联:下面就让我们一起来看看这些关系究竟是什么,以及它们的区别在哪里. 1.关联 双向关联:C1- ...

  4. (转载)OC学习篇之---Foundation框架中的NSDirctionary类以及NSMutableDirctionary类

    昨天学习了Foundation框架中NSArray类和NSMutableArray类,今天来看一下Foundation框架中的NSDirctionary类,NSMutableDirctionary类, ...

  5. [翻译]HTML中不知名的语义标签

    原文:http://docs.webplatform.org/wiki/tutorials/Lesser_-_known_semantic_elements HTML5中比较常用的语义元素有heade ...

  6. LeetCode(1) -Two Sum

    题目要求很简单,给你一个数组(例如,nums = [2,7,11,15])和一个target(target = 9),找到数组里两个数相加后能得到target的这两个数的index.在本例中,返回的应 ...

  7. URAL-1989 Subpalindromes 多项式Hash+树状数组

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1989 题意:给出一个字符串,m个操作:1,修改其中一个字符串,2,询问 [a, b] 是 ...

  8. 监听mysql是否挂了

    监听mysql是否挂了,如果挂了就重启mysql 方式一: #!/bin/bash pgrep -x mysqld &> /dev/null if [ $? -ne 0 ] then e ...

  9. CentOS(RedHat) 6.2 Samba share权限拒绝访问

    在实现<CentOS(RedHat) 6.2下Samba配置>的过程中,发现CentOS 6.2的Samba share总是没有权限写文件,已经试过在Windows XP/Windows  ...

  10. HDU 4499 Cannon (暴力求解)

    题意:给定一个n*m个棋盘,放上一些棋子,问你最多能放几个炮(中国象棋中的炮). 析:其实很简单,因为棋盘才是5*5最大,那么直接暴力就行,可以看成一行,很水,时间很短,才62ms. 代码如下: #i ...