B. Testing Robots
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 x, y, x0, 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 test(s)
Input
3 4 2 2
UURDRDRL
Output
1 1 0 1 1 1 1 0 6
Input
2 2 2 2
ULD
Output
1 1 1 1
Note

In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: .

对于这题笔者认为就是简单的模拟题:

但是在这千万不能用数组和循环结构的形式来解决实现这个问题,因为有可能会导致RuntimeError;

下面就贴出笔者的代码:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<string.h>
#include<algorithm>
#include<cmath>
const int N = 30;
const int inf=-100000;
using namespace std;

int g[510][510];
int num;
int X,Y,X0,Y0,xx,yy;
int fun(char c)
{
int flag=0;
switch(c)
{
case'R':
if(yy<Y)
yy++;
break;
case'L':
if(yy>1)
yy--;
break;
case'U':
if(xx>1)
xx--;
break;
case'D':
if(xx<X)
xx++;
break;
}
if(g[xx][yy]==0)
{
flag=1;
num--;
}
g[xx][yy]=1;
return flag;
}
int main()
{
//int x,y,x0,y0;
char str[100010];
scanf("%d%d%d%d",&X,&Y,&X0,&Y0);
scanf("%s",str);
memset(g,0,sizeof(g));
num=X*Y;
num--;
xx=X0,yy=Y0;
g[X0][Y0]=1;
cout<<"1 ";
for(int i=0;i<strlen(str)-1;i++)
{
cout<<fun(str[i])<<" ";
}
if(fun(str[strlen(str)-1]))
{
num++;
cout<<num<<endl;
}
else
{
cout<<num<<endl;
}
return 0;
}

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

  1. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

  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 这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了. #include <bits/stdc++.h> using nam ...

  4. Codeforces Round #335 (Div. 2) B

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

  5. Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何

    C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...

  6. Codeforces Round #335 (Div. 2) D. Lazy Student 构造

    D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...

  7. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 动态规划

    C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/conte ...

  8. 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/ ...

  9. Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造

    题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...

随机推荐

  1. 微信企业号 jsSDK wx.config报invalid signature错误,导致api接口无法使用

    最近在做公司定制化的时候发现一个问题,使用微信的语音API的时候微信报错,错误信息为:the permission value is offline verifying 但是诡异的是:同样的代码在我们 ...

  2. AngularJS(2)-Scope作用域和控制器

    $scope: 根作用域 所有的应用都有一个 $rootScope,它可以作用在 ng-app 指令包含的所有 HTML 元素中. $rootScope 可作用于整个应用中.是各个 controlle ...

  3. Linux文件保护禁止修改、删除、移动文件等,使用chattr +i保护

    不让用户修改.删除文件等,使用 chattr保护 chattr命令的用法:chattr [ -RV ] [ -v version ] [ mode ] files… 最关键的是在[mode]部分,[m ...

  4. C# double float int string 与 byte数组 相互转化

    在做通信编程的时候,数据发送多采用串行发送方法,实际处理的时候多是以字节为单位进行处理的.在C/C++中 多字节变量与Byte进行转化时候比较方便 采用UNION即可废话少说看示例:typedef u ...

  5. hdu 5652 India and China Origins 并查集+逆序

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5652 题意:一张n*m个格子的点,0表示可走,1表示堵塞.每个节点都是四方向走.开始输入初始状态方格, ...

  6. hdu 2844 poj 1742 Coins

    hdu 2844 poj 1742 Coins 题目相同,但是时限不同,原本上面的多重背包我初始化为0,f[0] = 1;用位或进行优化,f[i]=1表示可以兑成i,0表示不能. 在poj上运行时间正 ...

  7. 2014年度辛星css教程夏季版第五节

    本小节我们讲解css中的”盒模型“,即”box model“,它通常用于在布局的时候使用,这个”盒模型“也有人成为”框模型“,其实原理都一样,它的大致原理是这样的,它把一个HTML元素分为了这么几个部 ...

  8. Timer组件

    1.常用属性 Interval 用于获取或设置Timer组件Tick事件发生的时间间隔,属性值不能小于1 制作左右飘摇窗体 private void timer1_Tick(object sender ...

  9. Kinetic使用注意点--canvas

    <virtual> new Canvas(width, height) 参数: width:canvas宽度 height:canvas高度 方法: applyShadow(shape, ...

  10. 开发设计模式(三)策略模式(Strategy Pattern)

    转自http://blog.sina.com.cn/s/blog_89d90b7c01017zrr.html 下面的环境是unity3d,用C#进行编码,当然有人会说这是在乱用模式,U3D不一定适合使 ...