- 题意:有(n)栋房子,每栋房子都有自己的颜色(c_i),你每次可以对连续的长度为(k)的区间改变任何房子的颜色,问最少多少次可以使得所有房子颜色相同.
- 题解:因为只有(100)中颜色,所以我们可以直接枚举颜色,然后去遍历房子,如果房子颜色和当前枚举的不符,那么我们操作的次数就要++,并且跳到(j+k+1)栋房子继续.
- 代码:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
int t;
int n,k;
int a[N];
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
cin>>n>>k;
rep(i,1,n){
cin>>a[i];
}
int ans=INF;
rep(i,1,100){
int cnt=0;
rep(j,1,n){
if(a[j]!=i){
cnt++;
j+=k-1;
}
}
ans=min(ans,cnt);
}
cout<<ans<<'
';
}
return 0;
}