Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, ..., pm with integer coordinates, do the following: denote its initial location by p0. First, the robot will move from p0 to p1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches p1, it'll move to p2, again, choosing one of the shortest ways, then to p3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.
While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.
The first line of input contains the only positive integer n (1 ≤ n ≤ 2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of n letters, each being equal either L, or R, or U, or D. k-th letter stands for the direction which Robot traveled the k-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation.
The only line of input should contain the minimum possible length of the sequence.
4
RURD
2
6
RRULDD
2
26
RRRULURURUULULLLDLDDRDRDLD
7
3
RLL
2
4
LRLR
4
The illustrations to the first three tests are given below.
The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.
题意:不明白
解法:每运动到一个点,如果之前有反向就+1,清空标记,然后记录当前方向,依次进行下去
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
map<char,int>q;
int main()
{
int flag=;
cin>>n;
cin>>s;
int num=;
for(int i=n-; i>=; i--)
{
flag=;
// q.clear();
if(s[i]=='R')
{
if(q['L']==)
{
flag=;
// num++;
// q['L']=0;
// continue;
}
}
if(s[i]=='L')
{
if(q['R']==)
{
flag=;
// num++;
// q['R']=0;
// continue;
}
}
if(s[i]=='D')
{
if(q['U']==)
{
flag=;
// num++;
// q['U']=0;
// continue;
}
}
if(s[i]=='U')
{
if(q['D']==)
{
flag=;
// num++;
// q['D']=0;
// continue;
}
}
if(flag==)
{
num++;
q.clear();
}
q[s[i]]=;
}
cout<<num<<endl;
return ;
}
Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C的更多相关文章
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B
Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!
A. Santa Claus and a Place in a Class 模拟题.(0:12) 题意:n列桌子,每列m张桌子,每张桌子一分为2,具体格式看题面描述.给出n,m及k.求编号为k的桌子在 ...
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...
- codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法
A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- Android新组件CardView
Android L以后,新增了一个CardView组件,Google官方应用中有不少地方是使用卡片来展示信息,背后应该就是这个CardView. 使用CardView要引入单独的support包:co ...
- 如何理解C#委托
一:从下面的例子开始,理解委托变量本质 如上图,Condition是我定义的委托变量.这个委托变量的本质就是地址变量(即C语言当中的指针变量),它保存的是方法的入口地址. 当函数的调用者传递实参给这个 ...
- 二、oracle数据库成功安装步骤 配置监听器
Oracle数据库使用监听器来接收客户端的连接请求,要使客户端能连接Oracle数据库,必须配置监听程序. 在安装Oracle数据库时,如果选择的是"创建和配置数据库",则安装 ...
- win10快速开机
百度经验:jingyan.baidu.com 在win8系统出现以后的win系统中,都有一个特点,那就是快速启动,可是,相信大家都有这样一个问题,就是,自己明明用的是win8(或者win10)系统,可 ...
- Linux(Ubuntu)环境下使用Fiddler
自己的开发环境是Ubuntu, 对于很多优秀的软件但是又没有Linux版本这件事,还是有点遗憾的.比如最近遇到一个问题,在分析某个网站的请求路径和cookie时就遇到了问题.本来Chome浏览器自带的 ...
- AS3中 Event 类的target和currentTarget属性
在事件处理过程中,会自动生成事件类的实例,并传给侦听器函数.通过这个参数就可以使用事件类的属性和方法.其中target与currentTarget属性是两个很相似的属性. 对于简单的事件处理过程,分清 ...
- [Asp.net]Uploadify上传大文件,Http error 500 解决方案
/// 原来这个项目中用了这个控件 所以config设置文件大小没有 现在可以了 <location path="MailWrite.aspx" > <!--上传 ...
- 阿里云推荐码 hut29f
阿里云 推荐码 hut29f,适用于新手首次购买.
- 推荐!手把手教你使用Git
推荐!手把手教你使用Git 原文出处: 涂根华的博客 http://blog.jobbole.com/78960/ 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与 ...
- jQuery入门教程
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,博客地址为http://www.cnblogs.com/jasonnode/ .网站上有对应每一 ...