A9430 | Domino Effect
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges $n$ dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Chris arranges $n$ dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
输入格式
The first line contains a single integer $n$ ( $1<=n<=3000$ ), the number of the dominoes in the line. The next line contains a character string $s$ of length $n$ . The $i$ -th character of the string $s_{i}$ is equal to
- "L", if the $i$ -th domino has been pushed to the left;
- "R", if the $i$ -th domino has been pushed to the right;
- ".", if the $i$ -th domino has not been pushed.
It is guaranteed that if $s_{i}=s_{j}=$ "L" and $i<j$ , then there exists such $k$ that $i<k<j$ and $s_{k}=$ "R"; if $s_{i}=s_{j}=$ "R" and $i<j$ , then there exists such $k$ that $i<k<j$ and $s_{k}=$ "L".
- "L", if the $i$ -th domino has been pushed to the left;
- "R", if the $i$ -th domino has been pushed to the right;
- ".", if the $i$ -th domino has not been pushed.
It is guaranteed that if $s_{i}=s_{j}=$ "L" and $i<j$ , then there exists such $k$ that $i<k<j$ and $s_{k}=$ "R"; if $s_{i}=s_{j}=$ "R" and $i<j$ , then there exists such $k$ that $i<k<j$ and $s_{k}=$ "L".
输出格式
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
输入输出样例
输入 #1
14 .L.R...LR..L..
输出 #1
4
输入 #2
5 R....
输出 #2
0
输入 #3
1 .
输出 #3
1
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted