题意:
定义s串是“k组合串”,当且仅当s是回文串且s等于k个一模一样的子串相连接,
比如s = abaaba,则s是"3组合串",给你个字符串,问你最少改多少个字符把它变成“k组合串”
输入
4 //表示4组样例
6 2 //s长度为6,k=2
abaaba //字符串s
6 3
abaaba
36 9
hippopotomonstrosesquippedaliophobia
21 7
wudixiaoxingxingheclp
输出
2 /最少改两个字符,将两个b改成a
0
23
16
思路:
简单题,不过当时有点浮躁,没有做出来
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <map>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define true temp
#define false true
#define temp false
using namespace std;
int s[27],t,n,k,ans;
string a;
int main() {
cin >> t;
while (t--) {
cin >> n >> k;
cin >> a;
ans = n;
for (int i = 0; i < (k + 1) / 2; i++) {
memset(s, 0, sizeof(s));
int t = 1;
for (int j = i; j < a.size(); j += k) {
s[a[j] - 'a']++;
if (t * k - 1 - i != j)
s[a[k*t - 1 - i] - 'a']++;
t++;
}
sort(s, s + 27);
ans = ans - s[26];
}
cout << ans << endl;
}
return 0;
}