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.

Input

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.

Output

The only line of input should contain the minimum possible length of the sequence.

Examples
input
4
RURD
output
2
input
6
RRULDD
output
2
input
26
RRRULURURUULULLLDLDDRDRDLD
output
7
input
3
RLL
output
2
input
4
LRLR
output
4
Note

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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的桌子在 ...

  6. 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,到每 ...

  7. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. PostgreSQL JSON函数

    https://www.postgresql.org/docs/9.6/static/functions-json.html PostgreSQL 9.6.1 Documentation Prev U ...

  2. cloudera learning6:Hadoop Security

    保证Hadoop安全的最有效方法是对cluster进行隔离(isolation,常用方法是把大集群划分若干个小集群). Hadoop安全措施的目的是防止好的人不小心做了坏的事,而非防止坏人坏事. Ke ...

  3. macOS sierra 10.12 Cocoapods 私有库

    使用Cocoapods创建私有podspec 见文章:http://www.cocoachina.com/ios/20150228/11206.html 或http://blog.wtlucky.co ...

  4. Redis数据类型介绍

    Redis 数据类型 Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). String(字符串) st ...

  5. SpringMVC常用配置-配置DispatcherServlet映射请求路径的方式

  6. PHP获取某个表与其他表的关联关系算法

    如图 电影movie有多个附表,如果通过movie表来找出多个与之关联的表. 本算法规则: 外键写法必须是X_id; A与B 1对多关系,中间表表名必须是A_B,且A_B,必须包含A_id,B_id外 ...

  7. JS 获取客户端操作系统

    function detectOS() {     var sUserAgent = navigator.userAgent;     var isWin = (navigator.platform ...

  8. (转)学习使用Jmeter做压力测试(三)--数据库测试

    数据库测试 JMeter可以做为Web服务器与浏览器之间的代理网关,以捕获浏览器的请求和Web服务器的响应,这样就可很容易的生成性能测试脚本. 根据脚本,JMeter可通过线程组来模拟真实用户对Web ...

  9. aspcms,2.x以上版本,保护栏目不可删除处理方法

    aspcms,2.x以上版本,保护栏目不可删除处理方法.首先找到\admin\_content\_Sort\AspCms_SortFun.asp这个文件.然后将if  isnul(id) then a ...

  10. paper 120:计算距离矩阵的函数的pdist和pdist2函数

    matlab中自带的计算距离矩阵的函数有两个pdist和pdist2.前者计算一个向量自身的距离矩阵,后者计算两个向量之间的距离矩阵.基本调用形式如下: D = pdist(X) D = pdist2 ...