301955: CF371A. K-Periodic Array
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
K-Periodic Array
题意翻译
定义:数组 $a$ 是 $k$ 周期性的当且仅当 $a$ 的长度可被 $k$ 整除,且将数组 $a$ 切成 $\dfrac{n}{k}$ 段后,这 $k$ 段之间彼此相等。(即相当于数组 $a$ 的周期长度是 $k$。) 例如,任何数组都是 $n$ 周期性的,其中 $n$ 是数组长度。$2\ 1\ 2\ 1\ 2\ 1$ 同时是 $2$ 周期性和 $6$ 周期性的。 对于给定的数组 $a$,保证数组 $a$ 仅由数字 $1$ 和 $2$ 组成,请找到要更改的最少元素数以使数组是 $k$ 周期性的。如果数组已经是 $k$ 周期性的了,那么所需的值等于 $0$。题目描述
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array $ a $ is $ k $ -period if its length is divisible by $ k $ and there is such array $ b $ of length $ k $ , that $ a $ is represented by array $ b $ written exactly ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF371A/53488bbee46df1b241cbadadd932aea80891152b.png) times consecutively. In other words, array $ a $ is $ k $ -periodic, if it has period of length $ k $ . For example, any array is $ n $ -periodic, where $ n $ is the array length. Array $ [2,1,2,1,2,1] $ is at the same time 2-periodic and 6-periodic and array $ [1,2,1,1,2,1,1,2,1] $ is at the same time 3-periodic and 9-periodic. For the given array $ a $ , consisting only of numbers one and two, find the minimum number of elements to change to make the array $ k $ -periodic. If the array already is $ k $ -periodic, then the required value equals $ 0 $ .输入输出格式
输入格式
The first line of the input contains a pair of integers $ n $ , $ k $ ( $ 1<=k<=n<=100) $ , where $ n $ is the length of the array and the value $ n $ is divisible by $ k $ . The second line contains the sequence of elements of the given array $ a_{1},a_{2},...,a_{n} $ ( $ 1<=a_{i}<=2 $ ), $ a_{i} $ is the $ i $ -th element of the array.
输出格式
Print the minimum number of array elements we need to change to make the array $ k $ -periodic. If the array already is $ k $ -periodic, then print 0.
输入输出样例
输入样例 #1
6 2
2 1 2 2 2 1
输出样例 #1
1
输入样例 #2
8 4
1 1 2 1 1 1 2 1
输出样例 #2
0
输入样例 #3
9 3
2 1 1 1 2 1 1 1 2
输出样例 #3
3