#K73157. Minimum Operations to Avoid Adjacent Duplicate Containers
Minimum Operations to Avoid Adjacent Duplicate Containers
Minimum Operations to Avoid Adjacent Duplicate Containers
You are given a sequence of containers, each containing a chemical represented by an integer. Your task is to determine the minimum number of operations required such that no two adjacent containers contain the same chemical.
In one operation, you can change the chemical type in a container to any arbitrary value. Formally, for an array \(A\) of length \(N\), you need to ensure that \(A_i \neq A_{i+1}\) for all \(1 \leq i < N\). It can be shown that the minimum number of operations required is equal to the sum over each consecutive block of identical elements of \(\lfloor \frac{\text{block_length}}{2} \rfloor\).
Solve this problem for multiple test cases.
inputFormat
The first line contains an integer \(T\), denoting the number of test cases.
Each test case consists of two lines:
- The first line contains an integer \(N\) representing the number of containers.
- The second line contains \(N\) integers separated by spaces, indicating the chemical types in the containers.
outputFormat
For each test case, output a single line containing the minimum number of operations required to ensure that no two adjacent containers have the same chemical type.
## sample3
5
1 2 2 3 4
4
1 1 1 1
6
1 2 2 2 2 3
1
2
2
</p>