目录

2020/07/18–2020/07/24周报(week11)

本周推荐

by iuiou

团队训练

2020.7.18 牛客多校第三场

2020.7.20 牛客多校第四场

2020.7.23 codeforces team pratice

范泽恒

专题

比赛

题目

恭天祥

专题

比赛

题目

刘怀远

专题

比赛

题目

为什么这破题当初能卡那么久

ac代码

ac代码

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int maxn = 2e5 + 5;
const double pi = acos(-1);
const int mod = 998244353;
 
int t, n;
char s[131074];
 
int cal(int l, int r, int c){
	int cnt = 0;
	for(int i = l; i <= r; ++i) if(s[i] != c) ++cnt;
	return cnt;
}
 
int dfs(int l, int r, char c){
	if(l == r) return s[l] != c;
	int res = 3e7;
	int mid = (l + r) >> 1;
	res = min(res, dfs(l, mid, c + 1) + cal(mid + 1, r, c));
	res = min(res, dfs(mid + 1, r, c + 1) + cal(l, mid, c));
	return res;
}
 
int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%d\n", &n);
		scanf("%s", s + 1);
		printf("%d\n", dfs(1, n, 'a'));
	}
}