zoukankan      html  css  js  c++  java
  • Codeforces Round #429 (Div. 2) 841A. Generous Kefa(签到题)

    A. Generous Kefa

    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».


    题意:每个人能不能分到均不相同的颜色气球……思路很简单,只要数目最多的颜色不超过人数就好了……(窝现在也就做做签到题了orz(○| ̄|_  ) )

    感觉用map比较好处理……就懒懒の用了map……2333333

     1 #include<iostream>   
     2 #include<algorithm>
     3 #include<string>
     4 #include<string.h>
     5 #include<map>
     6 using namespace std;
     7 int n, k;
     8 map<char, int>p;
     9 char s;
    10 int main()
    11 {
    12     while (cin >> n >> k)
    13     {
    14         p.clear();
    15         for (int i = 0; i < n; i++)
    16         {
    17             cin >> s;
    18             p[s]++;
    19         }
    20         map<char,int>::iterator ite;
    21         int maxx = 0;
    22         for (ite = p.begin(); ite != p.end(); ite++)
    23         {
    24             if (ite->second > maxx)
    25                 maxx = ite->second;
    26         }
    27         if (maxx > k) cout << "NO" << endl;
    28         else cout << "YES" << endl;
    29     }
    30     return 0;
    31 }
  • 相关阅读:
    Golang——面向对象
    Golang——排序算法
    python常用设计模式
    Golang基础——数据类型:指针
    Golang基础——数据类型:结构体
    Golang基础——数据类型:map
    css盒子模型
    css选择器以及样式优先级
    Android中finish()方法
    架构漫谈(二)认识概念是理解架构的基础
  • 原文地址:https://www.cnblogs.com/Egoist-/p/7396783.html
Copyright © 2011-2022 走看看