CodeForces 606B Testing Robots【读题题QAQ】

来源:互联网 发布:淘宝代金券怎么使用 编辑:程序博客网 时间:2024/06/05 00:57

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 xyx0y0 (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 to100 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

Input
3 4 2 2UURDRDRL
Output
1 1 0 1 1 1 1 0 6
Input
2 2 2 2ULD
Output
1 1 1 1

Hint

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



/*    题意:在n*m的地图中.刚开始位置(x0,y0)有一个机器人,给机器人一个指令字符串s,         L移动到y减小的方向;         R移动到y增大的方向;         U移动到x减小的方向;         D移动到x增大的方向;         (仅通过这里要知道坐标系是如下所示!WA了几次!QAQ!)         -|---------------->y          |          |           |           |           |          ↓x        当移动位置超过这个n*m的地图,机器人会在原地停留.机器人体内有一个code,当机器人执行完所有的指令时code会使该机器人爆炸.        在n*m个位置上,我们每次选择一个位置(不能重复)并在该位置埋下地雷,把这作为一次测试.        先输出中间路径是否访问过,访问过为0,没有为1,注意一开始的位置是1,最后的位置不输出(题目太难读了QAQ)        最后输出有多少组测试会使得机器人在执行完所有的指令时才发生爆炸.(其实就是你不能在中途埋个地雷把它炸死,只能让人家死在code上)            类型:读题题!!!    分析:直接模拟,然后求除了走过的方格以外,还有几个方格,另外有个坑,当最后一个位置没被访问过,可以埋雷,因为code和雷同时搞死机器人,         人家也是死在code上...*/#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int maxs = 100005;const int maxn = 505;int n,m,x,y;char s[maxs];int res[maxs];int vis[maxn][maxn];int main(){    while(~scanf("%d%d%d%d",&n,&m,&x,&y)){        memset(res,0,sizeof(res));        memset(vis,0,sizeof(vis));        scanf("%s",s);        int len=strlen(s);        res[0]=1;vis[x][y]=1;        for(int i=0;i<len;i++){            if(s[i]=='U'){                if(x>1){                    x--;                    if(!vis[x][y]){                        res[i+1]=1;                        vis[x][y]=1;                    }                }            }            if(s[i]=='D'){                if(x<n){                    x++;                    if(!vis[x][y]){                        res[i+1]=1;                        vis[x][y]=1;                    }                }            }            if(s[i]=='R'){                if(y<m){                    y++;                    if(!vis[x][y]){                        res[i+1]=1;                        vis[x][y]=1;                    }                }            }            if(s[i]=='L'){                if(y>1){                    y--;                    if(!vis[x][y]){                        res[i+1]=1;                        vis[x][y]=1;                    }                }            }        }        int sum=0;        for(int i=0;i<len;i++){            printf("%d ",res[i]);            sum+=res[i];        }        if(vis[x][y])            printf("%d\n",n*m-sum);        else{            printf("%d\n",n*m-sum+1);        }    }    return 0;}


0 0
原创粉丝点击