Codeforces 841A - Generous Kefa
题目链接:http://codeforces.com/problemset/problem/841/A
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».
题解:水水
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=;
char a[];
int main()
{
int n,k;
while(cin>>n>>k){
for(int i=;i<n;i++)
cin>>a[i];
sort(a,a+n);
int m=,t=;
for(int i=;i<n;i++){
if(a[i]==a[i-]){
t++;
if(t>m) m=t;
}
else t=;
}
if(m>k) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return ;
}
Codeforces 841A - Generous Kefa的更多相关文章
- 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【hash/判断字符串是否有一种字符个数大于m】
A. Generous Kefa time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 【codeforces841A】Generous Kefa
原题 A. Generous Kefatime limit per test:2 secondsmemory limit per test:256 megabytes input:standard i ...
- 【Codeforces Round #429 (Div. 2) A】Generous Kefa
[Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...
- Codeforces 580B: Kefa and Company(前缀和)
http://codeforces.com/problemset/problem/580/B 题意:Kefa有n个朋友,要和这n个朋友中的一些出去,这些朋友有一些钱,并且和Kefa有一定的友谊值,要求 ...
- codeforces 580D:Kefa and Dishes
Description When Kefa came to the restaurant and sat at a table, the waiter immediately brought him ...
- codeforces#580 D. Kefa and Dishes(状压dp)
题意:有n个菜,每个菜有个兴奋值,并且如果吃饭第i个菜立即吃第j个菜,那么兴奋值加ma[i][j],求吃m个菜的最大兴奋值,(n<=18) 分析:定义dp[status][last],statu ...
- codeforces Round#429 (Div2)
2017-08-20 10:00:37 writer:pprp 用头文件#include <bits/stdc++.h>很方便 A. Generous Kefa codeforces 84 ...
- Kefa and Park
#include<bits/stdc++.h> #define max 100005 using namespace std; int cats[max]; vector<int&g ...
随机推荐
- 20180318 一个VS2015运行DataTable问题
1. 环境VS 2015 社区版,使用"DataTable" 为了即使查看DataTable中的数据,点击放大镜 ,加载提示错误. 解决方案: 第一步: 第二步: “选项” -- ...
- vue 获取屏幕宽高 width height
/** * 获取屏幕宽高 */ Vue.prototype.getViewportSize = function(){ return { width: window.innerWidt ...
- PHP适配器模式
[IDatabase.php] <?php /** * 适配器模式 * 可以将不同的函数接口封装成统一的API * 应用举例1:数据库操作 mysql/mysqli/pdo * 应用举例2:缓存 ...
- 如何使用向量代表文档doc或者句子sentence
1.“句向量”简介word2vec提供了高质量的词向量,并在一些任务中表现良好. 关于word2vec的原理可以参考这几篇论文: https://arxiv.org/pdf/1310.4546.pdf ...
- 拖拽控件java版
Button vv = new Button("vvvv"); DragSource.getDefaultDragSource().createDefaultDragGestur ...
- Pytorch快速入门及在线体验
本文搭配了Pytorch在线环境,可以直接在线体验. Pytorch是Facebook 的 AI 研究团队发布了一个基于 Python的科学计算包,旨在服务两类场合: 1.替代numpy发挥GPU潜能 ...
- jenkins借助winscp传本地文件到远程服务器上
有这样的场景,我们的ftp上都是些重要的资料,所以大家基本只有可看的权限,只有部分管理人员有可读可写的权限,但是jenkins上基本使用的都是ftp的路径,这个时候就存在一些问题,某些开发需要将自己构 ...
- python shutil.copytree 解决目标目录存在的情况
直接修改copytree的实现即可,如下: #copytree中找到 os.makedirs(dst),加入判断,就这么简单 if not os.path.exists(dst): os.makedi ...
- 30.get和post的区别
POST和GET的区别 Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个 ...
- node.js初识09
1.node_module文件夹 如果你的require中没有写./,那么Node.js将该文件视为node_modules目录下的一个文件. 2.package.json文件 如果使用文件夹来统筹管 ...