CF2195C.Dice Roll Sequence
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider the following cube D where numbers x and 7−x lie on opposite sides:
Image generated by Nano Banana Pro.
A sequence b of integers from 1 to 6 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, [1,4,2] is a dice roll sequence, while [3,4,6,3] is not because 3 and 4 are not on adjacent sides of the dice. Additionally, [2,2,4] is not a dice roll sequence because 2 and 2 are on the same (not adjacent) side of the dice.
Given a sequence a of n integers from 1 to 6, you can perform the following operation any number of times (possibly zero).
- Select an index 1≤i≤n and an integer 1≤x≤6. Then, change the value of ai to x.
Please determine the minimum number of operations required to make a a dice roll sequence.
∗Two sides of the cube S and T are called adjacent if they share exactly one edge of the cube. Do note that this condition implies S=T as well.
考虑如下立方体 D,其中数字 x 与 7−x 位于立方体的相对面上:
图片由 Nano Banana Pro 生成。
若整数序列 b 的每个元素均取自 1 至 6,且满足以下条件,则称其为一个骰子滚动序列(dice roll sequence):
- 所有相邻的两个元素所对应的面在立方体上是相邻的∗。
例如,[1,4,2] 是一个骰子滚动序列;而 [3,4,6,3] 不是,因为 3 和 4 在骰子上不处于相邻的面上;此外,[2,2,4] 也不是骰子滚动序列,因为 2 和 2 对应的是立方体上的同一面(而非相邻面)。
给定一个长度为 n 的整数序列 a,其中每个元素均取自 1 至 6。你可以执行以下操作任意多次(包括零次):
- 选择一个下标 1≤i≤n 和一个整数 1≤x≤6,并将 ai 的值修改为 x。
请确定使 a 变为骰子滚动序列所需的最少操作次数。
∗ 立方体的两个面 S 与 T 称为相邻的,当且仅当它们恰好共享立方体的一条棱。注意:该定义隐含了 S=T。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤3⋅105).
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤6).
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤3⋅105)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤6)。
保证所有测试用例的 n 值之和不超过 3⋅105。
输出格式
For each test case, output the minimum number of operations required to make a a dice roll sequence.
对于每个测试用例,输出使 a 成为一个骰子序列所需的最少操作次数。
输入输出样例
输入#1
3 3 1 4 2 4 3 4 6 3 10 6 1 4 3 1 3 2 5 4 4
输出#1
0 1 4
说明/提示
For the first test case, the sequence a is [1,4,2]. As this is already a dice roll sequence, the answer is 0.
For the second test case, the sequence a is [3,4,6,3].
Changing exactly one element, you can get [3,5,6,3], which is a dice roll sequence.
For the third test case, the sequence a is [6,1,4,3,1,3,2,5,4,4].
Changing exactly 4 elements, you can get [5,1,4,2,1,3,2,1,5,4], which is a dice roll sequence.
对于第一个测试用例,序列 a 为 [1,4,2]。由于它本身已是一个骰子投掷序列,因此答案为 0。
对于第二个测试用例,序列 a 为 [3,4,6,3]。
只需修改恰好一个元素,即可得到 [3,5,6,3],这是一个骰子投掷序列。
对于第三个测试用例,序列 a 为 [6,1,4,3,1,3,2,5,4,4]。
只需修改恰好 4 个元素,即可得到 [5,1,4,2,1,3,2,1,5,4],这是一个骰子投掷序列。
输入解题思路,AI测评打分。不知道怎么写?