CodeForces 606B Testing Robots【读题题QAQ】

本文介绍了一种在限定地图上模拟机器人路径并进行测试的方法。根据初始位置和一系列移动指令,预测机器人在不同测试场景下的行为及可能遭遇的地雷位置。文章详细解释了模拟过程,并提供了一个完整的代码实现。

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 2
UURDRDRL
Output
1 1 0 1 1 1 1 0 6
Input
2 2 2 2
ULD
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;
}


### Codeforces Round 1028 (Div. 2) 目概述 Codeforces Round 1028 (Div. 2) 是一场包含多个算法问的比赛,涵盖了从简单到复杂的不同难度级别。以下是该比赛的部分目内容及简要说明: #### A. Gellyfish and Flower 在本中,有两个角色:Gellyfish 和 Flower。每个角色有两滴血量,分别用 \(a\) 和 \(c\) 表示 Gellyfish 的血量,用 \(b\) 和 \(d\) 表示 Flower 的血量[^3]。 获胜条件是攻击对方的最低血量,并比较双方的最低血量值。如果 Gellyfish 的最低血量小于 Flower 的最低血量,则 Gellyfish 获胜;否则,Flower 获胜。 #### B. Problem - B - Codeforces B 的具体内容未完全提供,但通常涉及数组、字符串或其他数据结构的操作。可以参考比赛页面获取完整描述。 #### C. Rectangles C 要求处理矩形的相关问。具体来说,给定一些矩形的边长信息,需要判断某些条件是否满足。时间限制为每组测试用例 2 秒,内存限制为 256 MB[^2]。输入和输出均为标准格式,详细规则可参考比赛页面。 ### 示例代码(A ) 以下是一个实现 A 逻辑的 C++ 程序: ```cpp #include <iostream> #include <algorithm> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; int mina = min(a, c); int minb = min(b, d); if (mina < minb) cout << "Flower" << endl; else cout << "Gellyfish" << endl; } } ``` 此代码通过多次循环取输入并计算两个角色的最低血量,最终输出获胜者名称。 ### 注意事项 - 比赛中的所有目均可以通过官方链接访问,例如 [Codeforces Round 1028 (Div. 2)](http://codeforces.com/contest/1028)[^2]。 - 每道目的详细规则和样例输入输出可在对应页面找到。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值