跳到正文

题解

题解:P15606 [ICPC 2021 Jakarta R] Uniform Maker

OvO_FgSn约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年3月4日
收录
2026年3月7日
更新
2026年11月12日
篇幅
约 1 分钟
题目
P15606

版本

  1. v2当前
  2. v1

写篇题解拯救一下社贡。


由于每个字符串位数是相等的,所以枚举每一位,目标字符取该位出现次数最多的字母,修改次数即为该位其他字母的总数。

代码

C++
#include <bits/stdc++.h>
using namespace std;
int n, m, ans, cnt[30];
string s[110];
inline int read(){
	int res = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9'){
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9'){
		res = res * 10 + c - '0';
		c = getchar();
	}
	return res * f;
}
int main(){
	n = read(), m = read();
	for (int i = 1; i <= n; i++) cin >> s[i];
	for (int i = 0; i < m; i++){
		memset(cnt, 0, sizeof(cnt));
		for (int j = 1; j <= n; j++)
			cnt[s[j][i] - 'a' + 1]++;
		int mx = 0;
		for (int j = 1; j <= 26; j++)
			mx = max(mx, cnt[j]);
		ans += n - mx;
	}
	printf("%d\n", ans);
	return 0;
}
原文