Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
2015-12-11 16:58
435 查看
B. Testing Robots
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 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'.
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 test(s)
input
output
input
output
Note
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that:
.
题目链接:点击打开链接
给出地图长宽以及起点, 紧接着给出移动指示, 输出每一步的命令数.
越界或者已经访问过输出0, 最后一步输出没有访问过的个数, 其他情况输出1.
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int x, y, x3, y3, x2, y2;
bool vis[505][505];
char s[MAXN];
int main(int argc, char const *argv[])
{
scanf("%d%d%d%d", &x, &y, &x3, &y3);
scanf("%s", s);
int len = strlen(s);
x2 = x3, y2 = y3;
printf("1 ");
vis[x2][y2] = true;
for(int i = 0; i < len - 1; ++i) {
int ans;
if(s[i] == 'U') {
if(x2 - 1 < 1) ans = 0;
else if(vis[x2 - 1][y2]) {
ans = 0;
--x2;
}
else {
ans = 1;
vis[--x2][y2] = true;
}
}
else if(s[i] == 'D') {
if(x2 + 1 > x ) ans = 0;
else if(vis[x2 + 1][y2]) {
ans = 0;
++x2;
}
else {
ans = 1;
vis[++x2][y2] = true;
}
}
else if(s[i] == 'L') {
if(y2 - 1 < 1 ) ans = 0;
else if(vis[x2][y2 - 1]) {
ans = 0;
--y2;
}
else {
ans = 1;
vis[x2][--y2] = true;
}
}
else if(s[i] == 'R') {
if(y2 + 1 > y) ans = 0;
else if(vis[x2][y2 + 1]) {
ans = 0;
++y2;
}
else {
ans = 1;
vis[x2][++y2] = true;
}
}
printf("%d ", ans);
}
int num = 0;
for(int i = 1; i <= x; ++i)
for(int j = 1; j <= y; ++j)
if(!vis[i][j]) num++;
printf("%d\n", num);
return 0;
}
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 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'.
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 test(s)
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
Note
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that:
.
题目链接:点击打开链接
给出地图长宽以及起点, 紧接着给出移动指示, 输出每一步的命令数.
越界或者已经访问过输出0, 最后一步输出没有访问过的个数, 其他情况输出1.
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int x, y, x3, y3, x2, y2;
bool vis[505][505];
char s[MAXN];
int main(int argc, char const *argv[])
{
scanf("%d%d%d%d", &x, &y, &x3, &y3);
scanf("%s", s);
int len = strlen(s);
x2 = x3, y2 = y3;
printf("1 ");
vis[x2][y2] = true;
for(int i = 0; i < len - 1; ++i) {
int ans;
if(s[i] == 'U') {
if(x2 - 1 < 1) ans = 0;
else if(vis[x2 - 1][y2]) {
ans = 0;
--x2;
}
else {
ans = 1;
vis[--x2][y2] = true;
}
}
else if(s[i] == 'D') {
if(x2 + 1 > x ) ans = 0;
else if(vis[x2 + 1][y2]) {
ans = 0;
++x2;
}
else {
ans = 1;
vis[++x2][y2] = true;
}
}
else if(s[i] == 'L') {
if(y2 - 1 < 1 ) ans = 0;
else if(vis[x2][y2 - 1]) {
ans = 0;
--y2;
}
else {
ans = 1;
vis[x2][--y2] = true;
}
}
else if(s[i] == 'R') {
if(y2 + 1 > y) ans = 0;
else if(vis[x2][y2 + 1]) {
ans = 0;
++y2;
}
else {
ans = 1;
vis[x2][++y2] = true;
}
}
printf("%d ", ans);
}
int num = 0;
for(int i = 1; i <= x; ++i)
for(int j = 1; j <= y; ++j)
if(!vis[i][j]) num++;
printf("%d\n", num);
return 0;
}
相关文章推荐
- 用spring-session来管理http session
- 【LEETCODE】241-Different Ways to Add Parentheses
- UISegmentedControl
- 基于Source和正则表达式的Scala网页内容抓取
- Mybatis 动态sql
- 模式识别之预测---一元线性回归
- ThinkPHP去掉链接的index.php WAMP架构
- Android应用内存优化-图片如何优化
- android 源码编译环境配置
- nginx 操作
- vs2010 .net调用Webservice(客户端)
- nginx 操作
- 数据库事物四大特性-ACID
- HDU 4512——吉哥系列故事——完美队形I——————【LCIS应用】
- Oracle更改redo log的大小
- 在OS X 10.11上安装cocoapods时出现错误
- Redis 学习手册之redis安装和配置
- [置顶] 衣服颜色暴露女人性格,气质.....你是哪一种?
- leetcode之Ugly Number II
- android x264 编码 h264 demo