A1154 | [COCI-2008_2009-contest2]#5 SETNJA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
In an infinite binary tree:
• Each node has exactly two children – a left and a right child.
• If a node is labeled with the integer X, then its left child is labeled 2·X and its right child 2·X+
1.
• The root of the tree is labeled
1.
A walk on the binary tree starts in the root. Each step in the walk is either a jump onto the left child, onto the right child, or pause for rest (stay in the same node).
A walk is described with a string of letters 'L', 'R' and 'P':
• 'L' represents a jump to the left child;
• 'R' represents a jump to the right child;
• 'P' represents a pause.
The value of the walk is the label of the node we end up on. For example, the value of the walk LR is 5, while the value of the walk RPP is
3.
A set of walks is described by a string of characters 'L', 'R', 'P' and '*'. Each '*' can be any of the three moves; the set of walks contains all walks matching the pattern.
For example, the set L*R contains the walks LLR, LRR and LPR. The set ** contains the walks LL, LR, LP, RL, RR, RP, PL, PR and PP.
Finally, the value of a set of walks is the sum of values of all walks in the set.
Calculate the value of the given set of walks.
• Each node has exactly two children – a left and a right child.
• If a node is labeled with the integer X, then its left child is labeled 2·X and its right child 2·X+
1.
• The root of the tree is labeled
1.
A walk on the binary tree starts in the root. Each step in the walk is either a jump onto the left child, onto the right child, or pause for rest (stay in the same node).
A walk is described with a string of letters 'L', 'R' and 'P':
• 'L' represents a jump to the left child;
• 'R' represents a jump to the right child;
• 'P' represents a pause.
The value of the walk is the label of the node we end up on. For example, the value of the walk LR is 5, while the value of the walk RPP is
3.
A set of walks is described by a string of characters 'L', 'R', 'P' and '*'. Each '*' can be any of the three moves; the set of walks contains all walks matching the pattern.
For example, the set L*R contains the walks LLR, LRR and LPR. The set ** contains the walks LL, LR, LP, RL, RR, RP, PL, PR and PP.
Finally, the value of a set of walks is the sum of values of all walks in the set.
Calculate the value of the given set of walks.
输入格式
A string describing the set. Only characters 'L', 'R', 'P' and '*' will appear and there will be at most 10000 of them.
输出格式
Output the value of the set.
输入输出样例
输入 #1
P*P
输出 #1
6
输入 #2
L*R
输出 #2
25
输入 #3
**
输出 #3
33
In test data worth 30% points, there will be no characters '*'.
In test data worth 50% points, there will be at most three characters '*'.
In test data worth 50% points, there will be at most three characters '*'.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted