Generous Kefa
来源:互联网 发布:数据结构c语言课程设计 编辑:程序博客网 时间:2024/06/06 19:45
One day Kefa found n baloons. For convenience, we denote color ofi-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa hask friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give outall 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 andk (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 and4-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».
还是比较水的一道题。看看是不是有一个字母的数量大于k,如果大于的话,肯定会有人拿到2个相同的字母.
#include <iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<map>#include<string.h>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;int mp[30];int main(){ int n,k; scanf("%d %d",&n,&k); int ans=0; for(int i=1;i<=n;i++) { char now; scanf(" %c",&now); mp[now-'a'+1]++; ans=max(ans,mp[now-'a'+1]); } if(ans>k) printf("NO\n"); else printf("YES\n"); return 0;}
- Generous Kefa
- 429A. Generous Kefa
- Generous Kefa CodeForces
- A. Generous Kefa
- CF Generous Kefa(水)
- codeforces 841A Generous Kefa
- codeforces 841A Generous Kefa
- Codeforces 429 A. Generous Kefa
- Codeforces 841 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))
- Kefa and First Steps
- Kefa and Company
- Kefa and Park
- B. Kefa and Company
- 【JavaSE学习笔记】多线程02_Lock,死锁,等待唤醒机制,线程组和线程池,Timer定时器
- 使用反编译后的so文件
- react-native 下编写工具、Public类
- 栈和队列(习题)
- Python 实现爬取图片
- Generous Kefa
- C# 向MySQL数据库存储及读取图片、音乐等文件
- myeclipse中web项目出现红色叹号解决方案
- malloc/free和new/delete
- 【离散化+并查集】POJ_1733_Parity game
- CSS3基础学习 02-应用方式:内联、内部、外部
- Lua5.3 虚拟机指令分析(一)概述
- 涉及AbstractQueuedSynchronizer使用-CountDownLatch等
- B. Godsend