A11569 | Diagonal Walking
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements.
输入格式
The first line of the input contains one integer $n$ ( $1<=n<=100$ ) — the length of the sequence. The second line contains the sequence consisting of $n$ characters U and R.
输出格式
Print the minimum possible length of the sequence of moves after all replacements are done.
输入输出样例
输入 #1
5 RUURU
输出 #1
3
输入 #2
17 UUURRRRRUUURURUUU
输出 #2
13
In the first test the shortened sequence of moves may be DUD (its length is $3$ ).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is $13$ ).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is $13$ ).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted