1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import java.util.Scanner; import java.util.HashSet; import java.util.Iterator; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); HashSet<Integer> set = new HashSet<Integer>(); for(int i = 0; i < t; i++) { int n = input.nextInt(); int k = input.nextInt(); set.clear(); int[] house = new int[n]; for(int j = 0; j < n; j++) { int data = input.nextInt(); house[j] = data; set.add(data); } int minCount = n; for(Iterator<Integer> iterator = set.iterator(); iterator.hasNext();) { Integer nowColor = (Integer)iterator.next(); int count = 0; for(int x = 0; x < n;) { if(house[x] != nowColor) { x = x + k; count++; } else { x++; } } if(count < minCount) minCount = count; } System.out.println(minCount); } input.close(); } }
|