Codeforces Round #429 (Div. 2) A. Generous Kefa【hash/判断字符串是否有一种字符个数大于m】
2 seconds
256 megabytes
standard input
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.
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.
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
4 2
aabb
YES
6 3
aacaab
NO
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】的更多相关文章
- CodeForces 840C - On the Bench | Codeforces Round #429 (Div. 1)
思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意: 给出一个数组, ...
- CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)
思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上 ...
- CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...
- 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 解 只要不存在某个字母,它的 ...
- Codeforces Round #429 (Div. 2) 补题
A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...
- Codeforces Round #429 (Div. 2)
A. Generous Kefa One day Kefa found n baloons. For convenience, we denote color of i-th baloon as ...
- Codeforces Round #657 (Div. 2) A. Acacius and String(字符串)
题目链接:https://codeforces.com/contest/1379/problem/A 题意 给出一个由 '?' 和小写字母组成的字符串,可以将 '?' 替换为小写字母,判断是否存在一种 ...
- 【Codeforces Round #429 (Div. 2) A】Generous Kefa
[Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...
- 【Codeforces Round #429 (Div. 2) C】Leha and Function
[Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. ...
随机推荐
- oracle中准确控制job的下次运行时间(next date)
用过ORACLE的JOB的朋友也许都能够感觉到它的强大,和JAVA中的quartz有异曲同工之妙,可以少了很多的重复劳动:但是也会有许多问题,就是执行时间段和执行时间比较不容易确定. 这其实都是我们还 ...
- boost 字符串大小写转换
示例代码如下: #include <boost/algorithm/algorithm.hpp> #include <iostream> using namespace std ...
- 我的js运动库新
1.一些样式的获取和设置 //通过id获取当前元素 //params:id function $id(id) { return document.getElementById(id); } //向cs ...
- Vue.nextTick()的介绍和使用场景
每次都很好奇这个干嘛的,然后百度之后还是不明白.今天就彻彻底底好好的弄明白这是干嘛的!! 首先看一下vue文档 nextTick(),是将回调函数延迟在下一次DOM更新数据后调用,简单的理解是:当数据 ...
- Some vulnerabilities in JEECMSV9
转载:https://blog.csdn.net/weixin_44063566/article/details/88897406 之前遇到了一个JEECMS大概看了一下, 测试版本JEECMSV9. ...
- 一个班六个人,学号语文、数学、英语,接收成绩(不接受学号),输出学号成绩,总分、平均分,按总分排序(原生JS)
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Activiti实战03_Hello World
Hello World如此经典,以至于几乎学习没一门新的技术都是从Hello World开始,可能意味着开启了新世界的大门吧,接下来就让我们一起步入到Activiti的世界中吧! 本文所使用开发环境 ...
- Cocos2dx 3.0 过渡篇(二十八)C++11强类型枚举
一朋友在微信朋友圈晒了张照片,随手点开大图,带着赞赏的眼光扫了下,恩,几个月不见.又美丽了...咦?等等,她戴的这是什么?酷炫的造型! 金属边框! 微型摄像头! 这不是传说中的谷歌眼镜么?土豪啊,还好 ...
- Python学习 备注(2)
由于python下许多框架都是在python2下的,python3向下不兼容 需安装python2 安装好后,使用pip安装python下的框架scrapy 总是报错,最后发现是包管理器,pip的版本 ...
- docker tomcat启动慢
镜像 https://hub.docker.com/r/errorlife/tomcat/ docker pull errorlife/tomcat