Codeforces Round #335 (Div. 2) B.Testing Robots
来源:互联网 发布:拉法叶舰案 知乎 编辑:程序博客网 时间:2024/05/22 19:34
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 sizex × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactlyx·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 strings, 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 thex coordinate, and moving down increases it.
The tests can go on for very long, so your task is to predict their results. For eachk from 0 to length(s) your task is to find in how many tests the robot will run exactlyk commands before it blows up.
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 axisX 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 from1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'.
Print the sequence consisting of (length(s) + 1) numbers. On thek-th position, starting with zero, print the number of tests where the robot will run exactlyk commands before it blows up.
3 4 2 2UURDRDRL
1 1 0 1 1 1 1 0 6
2 2 2 2ULD
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 <string.h>#define maxn 100005char op[maxn];int ans [maxn], Map[505][505];int main(){ int n, m, ex, ey, i; scanf("%d %d %d %d", &n, &m, &ex, &ey); scanf("%s", op); int len = strlen(op); ans[len] = n * m; for(i = 0;i < len;i++) { //printf("%d %d %c\n", ex, ey, op[i]); if(Map[ex][ey] == 0) { ans[len]--; ans[i] = 1; Map[ex][ey] = 1; }else ans[i] = 0; if(op[i] == 'U'){ if(ex > 1) ex--; } else if(op[i] == 'D'){ if(ex < n) ex++; } else if(op[i] == 'L'){ if(ey > 1) ey--; } else if(op[i] == 'R'){ if(ey < m) ey++; // printf("---\n"); } } for(i = 0;i <= len;i++) printf("%d%c", ans[i], i<len?' ':'\n');}
- Codeforces Round #335 (Div. 2) B. Testing Robots 模拟
- Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
- Codeforces Round #335 (Div. 2) B.Testing Robots
- Codeforces Round #335 (Div. 2) B. Testing Robots (模拟)
- Codeforces Round #335 (Div. 2) B. Testing Robots
- Codeforces Round #335 (Div. 2)-Testing Robots(模拟)
- 【Codeforces Round 335 (Div 2) B】【模拟】Testing Robots 机器人逐步走 走到矿场就爆炸的最多行走步数
- CF 335 div.2-B/606B Testing Robots(读不懂题系列)
- Codeforces Round #350 (Div. 2) - B. Game of Robots (STL)
- Codeforces Round #350 (Div. 2) B. Game of Robots __ interesting
- Codeforces 606B Testing Robots 【模拟】
- CodeForces 606 B. Testing Robots(水~)
- Codeforces 606 B Testing Robots【模拟】
- CodeForces 606B Testing Robots【读题题QAQ】
- Codeforce Round#350(Div. 2) 670B Game of Robots
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Android 源码解析: 图片加载库Picasso 3 核心类
- swift !?
- Android:shape:表示一张图片
- leetcode -- Search for a Range -- 思路简单,要再做一遍
- 设计模式-装饰模式
- Codeforces Round #335 (Div. 2) B.Testing Robots
- wget FTP下载问题
- Linux异步IO+实例(POSIX IO与 libaio)
- 数据结构-后缀数组
- oracle日期to_char,mysql日期date_format,Sqlserver日期convert示例解析
- 第九周项目四----广义表算法库及应用1
- [Leetcode]Bulls and Cows
- java中的集合之Map接口(四)
- SVN相关