Codeforces Round #335 (Div. 2) B. Testing Robots 模拟
来源:互联网 发布:net是哪里的域名 编辑:程序博客网 时间:2024/05/22 05:25
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.
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'.
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.
3 4 2 2UURDRDRL
1 1 0 1 1 1 1 0 6
2 2 2 2ULD
1 1 1 1
#include <cstdio>#include <iostream>#include <vector>#include <algorithm>#include <cmath>#include <cstring>using namespace std;#define inf 0x3f3f3f3f#define maxn 100111typedef long long ll;char s[maxn];int dir[222],a[maxn],g[505][505];int main(){#ifdef CDZSC_Junefreopen("t.txt","r",stdin);#endifint x,y,x0,y0,sum,cnt;dir['U'] = -1,dir['D'] = 1;dir['L'] = -1,dir['R'] = 1;while(~scanf("%d%d%d%d",&x,&y,&x0,&y0)){memset(g,0,sizeof(g));sum = 1, cnt = 1;scanf("%s",s);int len = strlen(s);a[cnt++] = 1;g[x0][y0] = 1;for(int i = 0; i< len - 1; i++){if(s[i] == 'L'){if(y0 + dir['L'] >= 1){if(!g[x0][y0 + dir['L']]){a[cnt++] = 1;sum++;g[x0][y0 + dir['L']] = 1;}else{a[cnt++] = 0;}y0 += dir['L'];}else{a[cnt++] = 0;}}else if(s[i] == 'R'){if(y0 + dir['R'] <= y){if(!g[x0][y0 + dir['R']]){ sum++;a[cnt++] = 1;g[x0][y0 + dir['R']] = 1;}else{a[cnt++] = 0;}y0 += dir['R'];}else{a[cnt++] = 0;}}else if(s[i] == 'U'){if(x0 + dir['U'] >= 1){if(!g[x0 + dir['U']][y0]){ sum++;a[cnt++] = 1;g[x0 + dir['U']][y0] = 1;}else{a[cnt++] = 0;}x0 += dir['U'];}else{a[cnt++] = 0;}}else if(s[i] == 'D'){if(x0 + dir['D'] <= x){if(!g[x0 + dir['D']][y0]){sum++;a[cnt++] = 1;g[x0 + dir['D'] ][y0] = 1;}else{a[cnt++] = 0;}x0 += dir['D'];}else{a[cnt++] = 0;}}}printf("%d",a[1]);for(int i = 2; i< cnt; i++){printf(" %d",a[i]);}printf(" %d\n",x*y - sum);}}
- 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)-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 606B Testing Robots 【模拟】
- Codeforces 606 B Testing Robots【模拟】
- Codeforces Round #323 (Div. 2) B 模拟
- Codeforces Round #362 (Div. 2) B 模拟
- Codeforces Round #315 (Div. 2) B 模拟
- Codeforces Round #105 (Div. 2) B 模拟
- Codeforces Round #392 (Div. 2)B (模拟)
- 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 Round #256 (Div. 2) B. Suffix Structures(模拟)
- 断言(ASSERT)的用法
- 全局变量名前面的extern
- android学习笔记——Intent
- Linux(1)---文件搜索命令
- ZooKeeper 搭建附录
- Codeforces Round #335 (Div. 2) B. Testing Robots 模拟
- iOS之小知识点
- android学习笔记——Activity的调用小技巧
- iOS开发效率篇——Xcode优秀插件使用(持续更新中)
- POJ 1007 DNA 排序
- win7系统下配置openCV python环境附加 numpy +scipy安装
- appium_android 环境搭建
- 183 Examine the following command that is used to duplicate a database on the same host: RMAN> RUN {
- Win8或Win2012怎么添加桌面图标