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 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 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: .

这题的意思是没有走过的,如果走到了,就算一次 。以前走过的,现在再走一次,不会爆炸。始终没有走过的,一共有多少种-已经走过的,就是可能爆炸的可能次数

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int i,j;
int n,m;
int sum,ans,flag;
int a[510][510];
int x,y,x0,y0;
string s;
int main()
{
cin>>x>>y>>x0>>y0;
cin>>s;
sum=0;
for(i=0; i<s.length(); i++)
{
if(!a[x0][y0])
{
++sum;
cout<<"1"<<" ";
a[x0][y0]=1;
}
else
{
cout<<"0"<<" ";
}
if(s[i]=='L')
{
y0--;
}
else if(s[i]=='R')
{
y0++;
}
else if(s[i]=='U')
{
x0--;
}
else if(s[i]=='D')
{
x0++;
}
if(x0<=0)
{
x0=1;
}
else if(x0>x)
{
x0=x;
}
if(y0<=0)
{
y0=1;
}
else if(y0>y)
{
y0=y;
}
}
cout<<x*y-sum<<endl;
return 0;
}

  

最新文章

  1. jQuery源代码学习之六——jQuery数据缓存Data
  2. telerik 某些ajax拿数据方式下 load on demand 不起作用
  3. 阿里云OSS上传图片,并使用图片服务裁切
  4. js基础第四天
  5. 服务启动项 Start类型详解
  6. SQL查询四舍五入 解决方法
  7. 关于WSL(Windows上的Linux子系统)的介绍
  8. 【后缀自动机】洛谷P3804模板题
  9. 从PRISM开始学WPF(九)交互Interaction?
  10. XXX系统项目分析
  11. ILBC 运行时 (ILBC Runtime) 架构
  12. ADC转换的分辨率
  13. Android--保持加速度传感器在屏幕关闭后运行(收集)
  14. webpack的一些详细配置
  15. java设计模式-----20、模板方法模式
  16. linearLayout 和 relativeLayout的属性区别(转)
  17. lambda expressions are not supported at this language level
  18. KMP(http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&amp;problemid=2772)
  19. Springboot 如何加密,以及利用Swagger2构建Restful API
  20. Atom 检测php错误扩展linter-php

热门文章

  1. import time
  2. cocos2d-js 浏览器与JSB内存管理机制的不同
  3. 数字图像处理实验(7):PROJECT 04-03 , Lowpass Filtering 标签: 图像处理MATLAB 2017-05-25 09:30 109人
  4. Luogu 3521 [POI2011]ROT-Tree Rotations
  5. GPG入门 - 练习笔记
  6. XML DTD语法详解
  7. 转换流 Properties集合 序列化 工具
  8. Ubuntu学习小结(二)PostgreSQL的使用,进程的查看关闭,编辑器之神Vim入门
  9. appium自动化安装(一)
  10. 【AutoResetEvent】