Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
2 seconds
256 megabytes
standard input
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.
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 2
UURDRDRL
1 1 0 1 1 1 1 0 6
2 2 2 2
ULD
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: .
题目链接:点击打开链接
给出地图长宽以及起点, 紧接着给出移动指示, 输出每一步的命令数.
越界或者已经訪问过输出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;
}
Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)的更多相关文章
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...
- Codeforces Round #335 (Div. 2)B. Testing Robots解题报告
B. Testin ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 模拟
A. Magic Spheres Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #335 (Div. 2)
水 A - Magic Spheres 这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了. #include <bits/stdc++.h> using nam ...
- Codeforces Round #335 (Div. 2) B
B. Testing Robots time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何
C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...
随机推荐
- shell-001
for: shell_test #!/bin/bash var= var=$var+ echo $var mkdir only_a_joke shell_joke #!/bin/bash ./shel ...
- Python GUI 之 Treeview 学习
例子1 from tkinter import *import tkinter.ttk as ttk win = Tk()win.title("Treeview 学习") col ...
- 【二叉树】hdu 1710 Binary Tree Traversals
acm.hdu.edu.cn/showproblem.php?pid=1710 [题意] 给定一棵二叉树的前序遍历和中序遍历,输出后序遍历 [思路] 根据前序遍历和中序遍历递归建树,再后续遍历输出 m ...
- ubuntu mysql安装及需要其他主机连服务器mysql时的设置(error:10061)
说明: 一个朋友在使用ubuntu-server 16.04安装mysql,设置远程访问的时候出现了问题,请我帮忙.但是,我也没有使用过ubuntu安装mysql,于是乎搜索了很多技术文件,比着葫芦画 ...
- Java面试题集(二)
51.设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1,写出程序. 以下程序使用内部类实现线程,对j增减的时候没有考虑顺序问题. public class ThreadTest1 ...
- NOJ 1116 哈罗哈的大披萨 【淡蓝】 [状压dp+各种优化]
我只能说,珍爱生命,远离卡常数的题...感谢陈老师和蔡神,没有他们,,,我调一个星期都弄不出来,,,, 哈罗哈的大披萨 [淡蓝] 时间限制(普通/Java) : 1000 MS/ 3000 MS ...
- Resin Thread Dump
[2015/08/25 20:50:13.254] {ThreadLauncher2[ThreadPool[system]]-1} Thread Dump generated Tue Aug 25 2 ...
- 关于内存 转载自http://blog.csdn.net/xluren/article/details/8150723
首先感谢下原作者,写的真的非常明白,非常详细 1.预备知识—程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局 ...
- Redis命令行之Set
一.Redis之Set简介 1. Set是String类型的无序集合(元素成员唯一). 2. Set是通过hash表实现的,添加.删除.查找的复杂度都是O(1). 3. 每个集合最大成员数为232-1 ...
- Codeforces 848B Rooter's Song(分类+模拟)
题目链接 Rooter's Song 题意 有n个舞者站在x轴上或y轴上,每个人有不同的出发时间.x轴上的舞者垂直x轴正方向移动,y轴上的舞者垂直y轴正方向移动. 当x轴的舞者和y轴的舞者相遇时,他 ...