Codeforces Round #335 (Div. 2) B
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: .
这题的意思是没有走过的,如果走到了,就算一次 。以前走过的,现在再走一次,不会爆炸。始终没有走过的,一共有多少种-已经走过的,就是可能爆炸的可能次数
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int i,j;
int n,m;
int sum,ans,flag;
int a[510][510];
int x,y,x0,y0;
string s;
int main()
{
cin>>x>>y>>x0>>y0;
cin>>s;
sum=0;
for(i=0; i<s.length(); i++)
{
if(!a[x0][y0])
{
++sum;
cout<<"1"<<" ";
a[x0][y0]=1;
}
else
{
cout<<"0"<<" ";
}
if(s[i]=='L')
{
y0--;
}
else if(s[i]=='R')
{
y0++;
}
else if(s[i]=='U')
{
x0--;
}
else if(s[i]=='D')
{
x0++;
}
if(x0<=0)
{
x0=1;
}
else if(x0>x)
{
x0=x;
}
if(y0<=0)
{
y0=1;
}
else if(y0>y)
{
y0=y;
}
}
cout<<x*y-sum<<endl;
return 0;
}
Codeforces Round #335 (Div. 2) B的更多相关文章
- 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. 1) C. Freelancer's Dreams 计算几何
C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 构造
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 动态规划
C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/conte ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
- Codeforces Round #335 (Div. 2)
水 A - Magic Spheres 这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了. #include <bits/stdc++.h> using nam ...
- 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 #335 (Div. 2) D. Lazy Student 贪心
D. Lazy Student Student Vladislav came to his programming exam completely unprepared as usual. He ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS
C. Sorting Railway Cars An infinitely long railway has a train consisting of n cars, numbered from ...
随机推荐
- 【274】Python 相关问题
一.中文编码 参考:Python 中文编码 Python中默认的编码格式是 ASCII 格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错. 解决方法为只要在文件开头加入如下代码,任 ...
- JAVA基础知识总结14(String、StringBuffer、StringBuilder)
1.String字符串: java中用String类进行描述.对字符串进行了对象的封装.这样的好处是可以对字符串这种常见数据进行方便的操作.对象封装后,可以定义N多属性和行为. 如何定义字符串对象呢? ...
- Android广播接收者
其实,在什么是广播的第一句就已经说明了广播有什么用了.对了,笼统一点讲就是用来传输数据的.具体一点说就是:1. 实现了不同的程序之间的数据传输与共享,因为只要是和发送广播的action相同的接受者都能 ...
- android 自定义控件之事件
首先,继承需要扩展的VIEW,然后在里面添加一个自己的事件方法,例如, oniconclick(myinterface pinterface){ minterface = pinterface; } ...
- Libcurl 简明使用指南
http://blog.csdn.net/weiling_shen/article/details/7620397 我们的程序中使用的是人家的Easy.h头文件.....完成文件的上传和下传. 尤其是 ...
- ZROI2018提高day3t1
传送门 分析 我们可以用贪心的思想.对于所有并没有指明关系的数一定是将小的放在前面.于是我们按顺序在每一个已经指明大小顺序的数前面插入所有比它小且没有指明关系的数.详见代码. 代码 #include& ...
- python运算优先级
运算符优先级(下面的优先级高) 运算符 描述 lambda Lambda表达式 or 布尔“或” and 布尔“与” not x 布尔“非” in not in 成员测试 is ...
- 《Head First Servlets & JSP》-7-使用JSP
学习的知识点 JSP,最后会变成一个servlet JSP最终或变成一个完整的servlet在Web应用中运行,只不过这个servlet类会由容器写好. JSP中的scriptlet 所谓script ...
- jQuery 基础 : 获取对象 根据属性、内容匹配, 还有表单元素匹配
指定元素中包含 id 属性的, 如: $("span[id]") <span id="span1" name="S1">AA ...
- WPF之MVVM模式(3)
有种想写一个MVVM框架的冲动!!! 1.Model中的属性应不应该支持OnPropertyChanged事件? 不应该.应该有ViewModel对该属性进行封装,由ViewModel提供OnProp ...