A. Generous Kefa
来源:互联网 发布:mysql sleep 函数 编辑:程序博客网 时间:2024/06/05 08:56
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 2aabb
YES
6 3aacaab
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».
解题说明:此题确保每个人拿到的气球不一样颜色,首先统计各色气球个数,然后判断够不够分即可。
// codeforece.cpp: 定义控制台应用程序的入口点。//#include<cstdio>#include<iostream>#include<string>#include<cstring>using namespace std;int main(){int n, k, i, b[100], a[123] = { 0 }, j;char s[100], ch;scanf("%d%d", &n, &k);scanf("%s", s);for (i = 0; i<n; i++){ch = s[i];a[ch] = a[ch] + 1;}for (i = 97; i<123; i++){if (a[i]>k){printf("NO\n");exit(0);}}printf("YES\n");return 0;}
- 429A. Generous Kefa
- A. Generous Kefa
- codeforces 841A Generous Kefa
- codeforces 841A Generous Kefa
- Codeforces 429 A. Generous Kefa
- Generous Kefa
- Codeforces-429-2-A Generous Kefa
- Codeforces Round #429 (Div. 2) 841A Generous Kefa(水)
- Codeforces Round #429 (Div. 2):A. Generous Kefa
- Codeforces Round #429 (Div. 2) | A. Generous Kefa
- A. Generous Kefa(Round #429 (Div. 2))
- Generous Kefa CodeForces
- CF Generous Kefa(水)
- Codeforces 841 Generous Kefa(模拟)
- A. Kefa and First Steps
- coderforce 580A Kefa and First Steps
- CodeForces 580A Kefa and First Steps
- Codeforces 580A Kefa and First Steps
- [算法]最长子数组问题
- 斯坦福大学CS224d基础1:线性代数回顾
- Flask学习记录,后面再整理
- 30分钟掌握ES6/ES2015核心内容(下)
- PLSQL打开锁直接编辑表数据时的一个小坑
- A. Generous Kefa
- TCP的ACK原理和延迟确认机制
- C++笔记_C和C++区别
- 学习html前三天的知识点回顾
- 读书:海明威的《老人与海》
- 【Java】统计文件中各单词数量
- 再谈链接、静态链接、动态链接
- centos7.3安装zabbix过程遇到的错误与排错方法
- 从输入URL到页面加载发生了什么