【codeforces841A】Generous Kefa
原题
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
input1
4 2
aabb
output1
YES
input2
6 3
aacaab
output2
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».
题目大意
给一串包含小写字母的字符串,每个字符代表不同颜色的气球,再给出一个人数,问能否把气球发完并保证不存在一个人拿2个相同颜色的气球。
解法
水题:只要保证数量最多的那种颜色的气球不超过人数即可
代码
#include<iostream>
#include<cstdio>
#include<string>
#define MAXX
using namespace std;
int g_n,g_k,g_cnt;
int a[30];
int main(){
string ch;
scanf("%d%d",&g_n,&g_k);
cin>>ch;
int len=ch.size();
for(int i=0;i<len;i++)
a[ch[i]-'a'+1]++;
for(int i=1;i<=26;i++)
if(a[i]>g_k){
cout<<"NO";
return 0;
}
cout<<"YES";
return 0;
}
【codeforces841A】Generous Kefa的更多相关文章
- 【Codeforces Round #429 (Div. 2) A】Generous Kefa
[Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...
- Codeforces Round #429 (Div. 2) A. Generous Kefa【hash/判断字符串是否有一种字符个数大于m】
A. Generous Kefa time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 线段树+哈希【CF580E】Kefa and Watch
线段树+哈希[CF580E]Kefa and Watch Description \(n\)个数的字符串,\(m + k\)个操作 1 l r k把\(l - r\)赋值为\(k\) 2 l r d询 ...
- 【独家】硅谷创业公司在中国常跌的五个坑|禾赛科技CEO李一帆柏林亚太周主题演讲
[独家]硅谷创业公司在中国常跌的五个坑|禾赛科技CEO李一帆柏林亚太周主题演讲 李一帆 Xtecher特稿作者 关注 Xtecher推荐 演讲者:李一帆 翻译:晓娜 网址:www.xt ...
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- 【原】谈谈对Objective-C中代理模式的误解
[原]谈谈对Objective-C中代理模式的误解 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这篇文章主要是对代理模式和委托模式进行了对比,个人认为Objective ...
- 【原】FMDB源码阅读(三)
[原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...
- 【原】Android热更新开源项目Tinker源码解析系列之一:Dex热更新
[原]Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Tinker是微信的第一个开源项目,主要用于安卓应用bug的热修复和功能的迭代. Tinker github地址:http ...
- 【调侃】IOC前世今生
前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...
随机推荐
- 从零开始搞监控系统(1)——SDK
目前市面上有许多成熟的前端监控系统,但我们没有选择成品,而是自己动手研发.这里面包括多个原因: 填补H5日志的空白 节约公司费用支出 可灵活地根据业务自定义监控 回溯时间能更长久 反哺运营和产品,从而 ...
- 运行程序显示丢失“MSVCR100D.dll”
前言 写了一个Dll注入工具,结果发现程序在其他机器上会出现丢失"MSVCR100D.dll".这个dll是vs2010自带的动态链接库,如果在没安装vs2010运行库的电脑中使用 ...
- MySQL数据迁移那些事儿
前言: 在平时工作中,经常会遇到数据迁移的需求,比如要迁移某个表.某个库或某个实例.根据不同的需求可能要采取不同的迁移方案,数据迁移过程中也可能会遇到各种大小问题.本篇文章,我们一起来看下 MySQL ...
- 在ActiveMQ中使用SingleConnectionFactory遇到的坑
我们在生产环境使用了ActiveMQ作为消息中间件,消息中间件连接到数据库对消息进行持久化. 最近发生了一个奇怪的事情,消费者端的生产日志总是报如下错误: The JMS connection has ...
- 前端的MySQL基础
前端MySQL 一.引言 MySQL是一个关系型数据库管理系统,在Web应用方面,MySQL是最好的应用之一.其主要的他点是体积小.速度块.总体成本低.源码开放 二.MySQL的构成 在我们开始学习M ...
- Select Screen 0 with xrandr Ask QuestionScreen 0" here describes your whole virtual display made of these two outputs: eDP-1-
Screen 0" here describes your whole virtual display made of these two outputs: eDP-1-1: physica ...
- Python re 截取文本中IP地址及用户名
文本示例: ts=2019-07-10T06:43:06523942Z pid=1875 tid=6320 version=e73c536 proto=http id=5a61a613e395f883 ...
- Ansible_处理失败的任务
一.Ansible处理任务失败 1.管理play中任务错误 1️⃣:Ansible评估任务的返回代码,从而确定任务是成功还是失败 2️⃣:通常而言,当任务失败时,Ansible将立即在该主机上中止pl ...
- 3*060-A 日志记录
电路检修遇到的问题: 今天在检修一块3060-A电路板时 发现 3.3V烫 但是3.3V路上的电容并没有短路 于是拆单片机 拆RS232EN 拆 FM24V 最后发现 原来是 1117 ...
- STM32串口编程易错点
注意 串口发送函数 使用STM官方的LIB 中的库函数发送之后 加一点延时 否则会错误 接收数据不正常 正确做法是 加上等待发送完成