题解——Codeforces Round #508 (Div. 2) T1 (模拟)

依照题意暴力模拟即可A掉

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
char s[100100];
int n,k,barrel[30];
int main(){
  scanf("%d %d",&n,&k);
  scanf("%s",s+1);
  for(int i=1;i<=n;i++)
     barrel[s[i]-‘A‘+1]++;
  int ans=0x3f3f3f3f;
  for(int i=1;i<=k;i++)
    ans=min(ans,barrel[i]);
  printf("%d\n",ans*k);
  return 0;
}

原文地址:https://www.cnblogs.com/dreagonm/p/9602502.html

时间: 2024-08-29 08:41:42

题解——Codeforces Round #508 (Div. 2) T1 (模拟)的相关文章

题解——Codeforces Round #508 (Div. 2) T2 (构造)

按照题意构造集合即可 注意无解情况的判断 #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <map> using namespace std; int n,sum; int main(){ scanf("%d",&n); if(n==1){ printf

题解——Codeforces Round #508 (Div. 2) T3 (贪心)

贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <queue> #define int long long using namespace std; int ansa=0,ansb=0,posa=1,posb=1,n,a[1000100],b[1000100]; bool c

题解Codeforces Round #595 (Div. 3)(CF1249)

开题1小时(雾)严重影响我的提交以及做题心情..我刚开题就发现有人阿克了.. 实际上这场div3真心简单良心很休闲. A:送分题,先排序,每次枚举一下这个数可以加到哪个集合里,加进去就行. 1 #include<stdio.h> 2 #include<algorithm> 3 #define it register int 4 #define il inline 5 using namespace std; 6 const int N=1000005; 7 int a[N],o[N

Codeforces Round #306 (Div. 2)——C模拟——Divisibility by Eight

You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit

题解Codeforces Round #597 (Div. 2)

A:送分,裸的gcd. 1 #include<stdio.h> 2 #define il inline 3 #define it register int 4 int T,a,b,d; 5 il void gcd(int a,int b){ 6 if(!b){d=a;return;} 7 gcd(b,a%b); 8 } 9 il void fr(int &num){ 10 num=0;char c=getchar();int p=1; 11 while(c<'0'||c>'

题解 Codeforces Round #615 (Div. 3) (CF1294)

A:判断一下和是不是3的倍数,由于只加不减,所以还要判断有没有大于和的1/3. 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #define it register int 5 #define ct const int 6 #define il inline 7 using namespace std; 8 int T,a,b,c,n,x; 9 namespace io{ 10 il c

Codeforces Round #508 (Div. 2)

A char s[100005]; int cnt[26]; void test_case() { int n, k; scanf("%d%d%s", &n, &k, s + 1); for(int i = 1; i <= n; ++i) ++cnt[s[i] - 'A']; int minL = INF; for(int i = 0; i < k; ++i) minL = min(minL, cnt[i]); printf("%d\n"

Codeforces Round #457 (Div. 2)

Codeforces Round #457 (Div. 2) A.模拟. B.模拟.比赛的时候这题出锅了,然后就unrated了.注意要先保证最大值最小,再保证字典序最大. C.构造.挑一个大于N的质数然后连啊连就可以了. D.可持久化Trie.弄两个Trie.一个记录字符串,另一个记录数字. 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 stru

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When