Codeforces Round #335 (Div. 2) B. Testing Robots (模拟)
来源:互联网 发布:淘宝素材主图怎么做 编辑:程序博客网 时间:2024/06/04 18:55
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
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: .
题意:n*m的地图,给定起点,然后给你行走的方向,然后让你输出路径,和最后没有走过的地方,如果之前走过了输出0,没有走过输出1,最后一步不算
思路:暴力模拟一下就行了
总结:这道题刚开始没看懂,写了一下样例都对不上,然后一个单词一个单词翻译,总算看懂了,英语是硬伤。。。
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 200010#define LL long long#define ll __int64#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;int v[510][510];char s[MAXN];int fab(int x){return x>0?x:-x;}int main(){int n,m,i,x,y;while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF){scanf("%s",s);mem(v);int len=strlen(s);int k=1;int cnt=1;v[x][y]=1;printf("1 ");for(i=0;i<len-1;i++){int a=x,b=y;if(s[i]=='U'){x--;if(x<1)x++;}else if(s[i]=='D'){x++;if(x>n)x--;}else if(s[i]=='R'){y++;if(y>m)y--;}else{y--;if(y<1)y++;}if(!v[x][y]){v[x][y]=1;printf("1 ");cnt++;}elseprintf("0 ");}printf("%d\n",n*m-cnt);}return 0;}
- 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(模拟)
- W8系统安装oracle11G出现环境配置低
- epoll详解
- ztree将后台传过来的json对象封装为子父集关系的json数组
- PhoneGap/Cordova学习笔记--4.使用HTML5进行页面布局
- SQL学习总结
- Codeforces Round #335 (Div. 2) B. Testing Robots (模拟)
- android性能优化
- Java 中4字节形式数据转换为float
- copy和mutableCopy
- 高性能分布式计算与存储设计概要
- 小心错误使用EasyUI 让网站性能减半
- POJ-1273 Drainage Ditches 最大流Dinic
- 解决NDK开发中Eclipse报错“Unresolved inclusion jni.h”的最终方法
- CV开发环境配置(Ubuntu)