【CodeForces】夜深人静写cf

简介: Problem - B - Codeforces

Problem - B - Codeforces 

8..png

8.1.png这道题的解法是真的妙

注意int会向下取整

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    map<int, int> a, A;
    for (auto c : s) {
      if (c >= 'a' && c <= 'z') a[c - 'a']++;
      else A[c - 'A']++;
    }
    int res = 0, cnt = 0;
    for (int i = 0; i < 26; i++) {
      res += min(a[i], A[i]);
      cnt += abs(a[i] - A[i]) / 2;
    }
    res += min(cnt, k);
    cout << res << endl;
  }
  return 0;
}

Code over!

相关文章
|
6月前
|
机器学习/深度学习 传感器 监控
12P3439X012/G6450081/A,KJ2003X1-BB1 VE3006
12P3439X012/G6450081/A,KJ2003X1-BB1 VE3006
31 0
|
5月前
|
Java
HDU 1570 AC
HDU 1570 AC
23 0
|
6月前
|
C++
hdoj 4288coder & cf 85d Sum of Medians
这两个题目是一样的,大概题意是有3个操作 add x, 在集合中加入x, del x 是删除x, sum 是求出由小到大排序后所有下标mod5等于3的数的和。
16 0
|
7月前
|
机器学习/深度学习 人工智能
CF1496A Split it!(数学分析)
CF1496A Split it!(数学分析)
26 0
|
11月前
luogu CF776D The Door Problem(2-sat问题)
luogu CF776D The Door Problem(2-sat问题)
46 0
|
11月前
cf 1042B(状压dp)
cf 1042B(状压dp)
46 0
CF711D-Directed Roads(组合数学 dfs找环)
CF711D-Directed Roads(组合数学 dfs找环)
62 0
CF711D-Directed Roads(组合数学 dfs找环)
|
存储 机器学习/深度学习 算法
Lec3 基于模型的 CF | 学习笔记
快速学习 Lec3 基于模型的 CF 。
109 0
Lec3 基于模型的 CF | 学习笔记
|
数据库
第六周 课后实践案例 出现 Incorrect string value: '\xC0\xD6\xC6\xF7' for column 'tName' at row 1
第六周 课后实践案例 出现 Incorrect string value: '\xC0\xD6\xC6\xF7' for column 'tName' at row 1
第六周 课后实践案例 出现 Incorrect string value: '\xC0\xD6\xC6\xF7' for column 'tName' at row 1
|
移动开发
洛谷P2639-[USACO09OCT]Bessie‘s Weight Problem G(01背包)
洛谷P2639-[USACO09OCT]Bessie‘s Weight Problem G(01背包)
洛谷P2639-[USACO09OCT]Bessie‘s Weight Problem G(01背包)

热门文章

最新文章