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 }
  • 相关阅读:
    《数据库原理》课程笔记 (Ch04-数据库管理系统)
    《数据库原理》课程笔记 (Ch03-数据库语言)
    《操作系统》课程笔记(Ch07-死锁)
    《数据库原理》课程笔记 (Ch02-数据模型)
    《数据库原理》课程笔记 (Ch01-引论)
    《计算机网络》课程笔记 (Ch02-应用层)
    《ES6标准入门》读书笔记 第5章
    《ES6标准入门》读书笔记 第4章
    《ES6标准入门》读书笔记 第3章
    《计算机网络》课程笔记 (Ch01-计算机网络和因特网)
  • 原文地址:https://www.cnblogs.com/Egoist-/p/7396783.html
Copyright © 2011-2022 走看看