A. Generous Kefa
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.

Next line contains string s — colors of baloons.

Output

Answer to the task — «YES» or «NO» in a single line.

You can choose the case (lower or upper) for each letter arbitrary.

Examples
input
4 2
aabb
output
YES
input
6 3
aacaab
output
NO
Note

In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.

In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».

【题意】:判断字符串是否有一种字符个数大于m。

【分析】:把每个字符映射为一个0~26的数值,判断数值出现的次数是否超过m。

【代码】:

#include<bits/stdc++.h>
using namespace std;
char a;
int mp[50];
int m,n;
int f;
int main()
{
while(cin>>n>>m)
{
getchar();//
for(int i=0;i<n;i++)
{
scanf("%c",&a);
mp[a-'a']++;
}
f=1;
for(int i=0;i<26;i++)
{
if(mp[i]!=0)
{
if(mp[i]>m)
{
f=0;
break;
}
}
}
if(f) puts("YES");
else puts("NO");
}
return 0;
}

  

int n, k; cin >> n >> k;
string s; cin >> s;
int cnt[] = {};
for (int i = ; i < s.size(); i++) {
cnt[s[i] - 'a']++;
}

string输入

char str[];
int a[];
scanf("%s",str);
int len=strlen(str);
memset(a,,sizeof(a));
for(int i=;i<len;i++)
{
a[str[i]-'a']++;
}

char字符数组

Codeforces Round #429 (Div. 2) A. Generous Kefa【hash/判断字符串是否有一种字符个数大于m】的更多相关文章

  1. CodeForces 840C - On the Bench | Codeforces Round #429 (Div. 1)

    思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意: 给出一个数组, ...

  2. CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)

    思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上 ...

  3. CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)

    /* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...

  4. Codeforces Round #429 (Div. 2/Div. 1) [ A/_. Generous Kefa ] [ B/_. Godsend ] [ C/A. Leha and Function ] [ D/B. Leha and another game about graph ] [ E/C. On the Bench ] [ _/D. Destiny ]

    PROBLEM A/_ - Generous Kefa 题 OvO http://codeforces.com/contest/841/problem/A cf 841a 解 只要不存在某个字母,它的 ...

  5. Codeforces Round #429 (Div. 2) 补题

    A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...

  6. Codeforces Round #429 (Div. 2)

    A. Generous Kefa   One day Kefa found n baloons. For convenience, we denote color of i-th baloon as  ...

  7. Codeforces Round #657 (Div. 2) A. Acacius and String(字符串)

    题目链接:https://codeforces.com/contest/1379/problem/A 题意 给出一个由 '?' 和小写字母组成的字符串,可以将 '?' 替换为小写字母,判断是否存在一种 ...

  8. 【Codeforces Round #429 (Div. 2) A】Generous Kefa

    [Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...

  9. 【Codeforces Round #429 (Div. 2) C】Leha and Function

    [Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. ...

随机推荐

  1. C++给组合框控件(Combo box)加变量后不能运行

    是一个BUG,找出你程序存储的位置,打开一个Debug的文件夹,将除.res文件之外的所有文件删除,然后运行,就可以了!!

  2. pandas一些基本操作(DataFram和Series)_4

    import numpy as np;import pandas as pd;kill_num=pd.Series([10,12,8,5,0,2,6])#击杀数量#青铜1200-2000#白银2001 ...

  3. Codeforces-348E Pilgrims

    #4342. CF348 Pilgrims 此题同UOJ#11 ydc的大树 Online Judge:Bzoj-4342,Codeforces-348E,Luogu-CF348E,Uoj-#11 L ...

  4. 跟我一起学习webpack(一)

    跟我一起打包我们的第一个应用 第一步安装webpack 接下来我们新建文件 //add-content.js export default function(){ document.write('he ...

  5. 阿里云 Aliplayer高级功能介绍(六):进度条标记

    基本介绍 Aliplayer在进度条上提示时间和缩略图功能外,还可以进行视频内容的提示打点,当然不止是进度条上显示打点的内容,还提供一组接口,方便用户进行打点时间和内容的获取, 基本UI如下图所示: ...

  6. Django项目:CRM(客户关系管理系统)--78--68PerfectCRM实现CRM业务流程(bpm)报名缴费分页

    # pagination.py # ————————68PerfectCRM实现CRM业务流程(bpm)报名缴费分页———————— from django.utils.safestring impo ...

  7. Nodejs Express目录结构

    原文  http://www.leixuesong.cn/1508 Express是一个基于Node.js平台的极简.灵活的web应用开发框架.在前面我们已经详细介绍了Express的安装,下面详细讲 ...

  8. 19-10-24-J-快乐?

    向未来的大家发送祝福(不接受的请自动忽略): 祝大家程序员节快乐! 好了. ZJ一下 额. 考场上差点死了. 码1h后,T1还没过大样例. 我×××. 后来发现是自己××了. T2T3丢暴力. 比咕的 ...

  9. vim之buffer 与 折叠

    常用的折叠命令有: zf zi zo zc zd zf10j从当前行向下10行创建折叠(共11行),zfj创建两行的折叠 常用的还有zf%. 进行多文件编辑时,会涉及到buffer的使用::ls 查看 ...

  10. eclipse环境问题-java版本不兼容

    有时候虽然我们给项目配置的jdk版本.项目编译版本都一直,但是还是会报如下的错误: Description Resource Path Location Type Java compiler leve ...