欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2195C.Dice Roll Sequence
Dice Roll Sequence
Consider the following cube where numbers and lie on opposite sides:
Image generated by Nano Banana Pro.
A sequence of integers from to is called a dice roll sequence if it satisfies the following condition:
- All pairs of adjacent elements lie on adjacent sides of the cube.
For example, is a dice roll sequence, while is not because and are not on adjacent sides of the dice. Additionally, is not a dice roll sequence because and are on the same (not adjacent) side of the dice.
Given a sequence of integers from to , you can perform the following operation any number of times (possibly zero).
- Select an index and an integer . Then, change the value of to .
Please determine the minimum number of operations required to make a dice roll sequence.
Two sides of the cube and are called adjacent if they share exactly one edge of the cube. Do note that this condition implies as well.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the minimum number of operations required to make a dice roll sequence.
Note
For the first test case, the sequence is . As this is already a dice roll sequence, the answer is .
For the second test case, the sequence is .
Changing exactly one element, you can get , which is a dice roll sequence.
For the third test case, the sequence is .
Changing exactly elements, you can get $[\color{red}{5},1,4,\color{red}{2},1,3,2,\color{red}{1},\color{red}{5},4]$, which is a dice roll sequence.
Samples
3
3
1 4 2
4
3 4 6 3
10
6 1 4 3 1 3 2 5 4 4
0
1
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |