【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!

相关文章
codeforces 318 A.Even Odds B.Sereja and Array
codeforces 318 A.Even Odds B.Sereja and Array
44 0
|
人工智能
codeforces 315 B.Sereja and Array
codeforces 315 B.Sereja and Array
54 0
codeforces 299 A. Ksusha and Array
题目就是让你找出一个数组中可以将这个数组中所有数整除的数,很明显,如果存在,这个数肯定是最小的一个。
50 0
Online Judge System 中术语含义: OJ、AC、WA、TLE、OLE、MLE、PE、RE、CE
Online Judge System 中术语含义: OJ、AC、WA、TLE、OLE、MLE、PE、RE、CE
3651 0
Online Judge System 中术语含义: OJ、AC、WA、TLE、OLE、MLE、PE、RE、CE
|
6月前
考核 baby.bc
考核 baby.bc
43 0
|
8月前
CF 1538 G. Gift Set (贪心+思维)
【6月更文挑战第14天】
49 0
|
机器学习/深度学习 传感器 监控
12P3439X012/G6450081/A,KJ2003X1-BB1 VE3006
12P3439X012/G6450081/A,KJ2003X1-BB1 VE3006
56 0
|
C++
hdoj 4288coder & cf 85d Sum of Medians
这两个题目是一样的,大概题意是有3个操作 add x, 在集合中加入x, del x 是删除x, sum 是求出由小到大排序后所有下标mod5等于3的数的和。
39 0
ABB PP846 3BSE042238R1 基于电子管的技术被点接触晶体管
ABB PP846 3BSE042238R1 基于电子管的技术被点接触晶体管
82 0
ABB PP846 3BSE042238R1 基于电子管的技术被点接触晶体管