A15217 | Cypher
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Luca has a cypher made up of a sequence of $n$ wheels, each with a digit $a_i$ written on it. On the $i$ -th wheel, he made $b_i$ moves. Each move is one of two types:
- up move (denoted by $\texttt{U}$ ): it increases the $i$ -th digit by $1$ . After applying the up move on $9$ , it becomes $0$ .
- down move (denoted by $\texttt{D}$ ): it decreases the $i$ -th digit by $1$ . After applying the down move on $0$ , it becomes $9$ .
Example for $n=4$ . The current sequence is 0 0 0 0.Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.
- up move (denoted by $\texttt{U}$ ): it increases the $i$ -th digit by $1$ . After applying the up move on $9$ , it becomes $0$ .
- down move (denoted by $\texttt{D}$ ): it decreases the $i$ -th digit by $1$ . After applying the down move on $0$ , it becomes $9$ .
Example for $n=4$ . The current sequence is 0 0 0 0.Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.
输入格式
The first line contains a single integer $t$ ( $1 \leq t \leq 100$ ) — the number of test cases.
The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 100$ ) — the number of wheels.
The second line contains $n$ integers $a_i$ ( $0 \leq a_i \leq 9$ ) — the digit shown on the $i$ -th wheel after all moves have been performed.
Then $n$ lines follow, the $i$ -th of which contains the integer $b_i$ ( $1 \leq b_i \leq 10$ ) and $b_i$ characters that are either $\texttt{U}$ or $\texttt{D}$ — the number of moves performed on the $i$ -th wheel, and the moves performed. $\texttt{U}$ and $\texttt{D}$ represent an up move and a down move respectively.
The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 100$ ) — the number of wheels.
The second line contains $n$ integers $a_i$ ( $0 \leq a_i \leq 9$ ) — the digit shown on the $i$ -th wheel after all moves have been performed.
Then $n$ lines follow, the $i$ -th of which contains the integer $b_i$ ( $1 \leq b_i \leq 10$ ) and $b_i$ characters that are either $\texttt{U}$ or $\texttt{D}$ — the number of moves performed on the $i$ -th wheel, and the moves performed. $\texttt{U}$ and $\texttt{D}$ represent an up move and a down move respectively.
输出格式
For each test case, output $n$ space-separated digits — the initial sequence of the cypher.
输入输出样例
输入 #1
3 3 9 3 1 3 DDD 4 UDUU 2 DU 2 0 9 9 DDDDDDDDD 9 UUUUUUUUU 5 0 5 9 8 3 10 UUUUUUUUUU 3 UUD 8 UUDUUDDD 10 UUDUUDUDDU 4 UUUU
输出 #1
2 1 1 9 0 0 4 9 6 9
In the first test case, we can prove that initial sequence was $[2,1,1]$ . In that case, the following moves were performed:
- On the first wheel: $2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9$ .
- On the second wheel: $1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3$ .
- On the third wheel: $1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1$ .
The final sequence was $[9,3,1]$ , which matches the input.
- On the first wheel: $2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9$ .
- On the second wheel: $1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3$ .
- On the third wheel: $1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1$ .
The final sequence was $[9,3,1]$ , which matches the input.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted