zoukankan      html  css  js  c++  java
  • Codeforces 841A

    题目链接: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.

    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
    Input
    4 2
    aabb
    Output
    YES
    Input
    6 3
    aacaab
    Output
    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».

     题解:水水

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <algorithm>
     6 #include <cmath>
     7 using namespace std;
     8 const int N=10005;
     9 char a[101];
    10 int main()
    11 {
    12     int n,k;
    13     while(cin>>n>>k){
    14         for(int i=0;i<n;i++)
    15             cin>>a[i];    
    16         sort(a,a+n);
    17         int m=0,t=1;
    18         for(int i=1;i<n;i++){
    19             if(a[i]==a[i-1]){
    20                 t++;
    21                 if(t>m) m=t;
    22             }
    23             else t=1;
    24         }
    25         if(m>k) cout<<"NO"<<endl;
    26         else cout<<"YES"<<endl;
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    Djnago中缓存配置(redis配置案例)
    HDU-4717 The Moving Points 三分
    HDU-4716 A Computer Graphics Problem 水题
    HDU-2686 Matrix 多进程DP
    [转]手动开平方的简易方法
    [转]树链剖分
    HUOJ-10857 最大的面积 凸包+DP
    Bnuoj-29359 Deal with numbers 线段树
    HDU-4283 You Are the One 区间DP
    BNUOJ-26586 Simon the Spider 最小生成树+枚举
  • 原文地址:https://www.cnblogs.com/wydxry/p/7428185.html
Copyright © 2011-2022 走看看