zoukankan      html  css  js  c++  java
  • 【codeforces 757A】Gotta Catch Em' All!

    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.

    Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word “Bulbasaur” (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of “Bulbasaur” must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word “Bulbasaur” from the newspaper.

    Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?

    Note: uppercase and lowercase letters are considered different.

    Input
    Input contains a single line containing a string s (1  ≤  |s|  ≤  105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.

    The string s contains lowercase and uppercase English letters, i.e. .

    Output
    Output a single integer, the answer to the problem.

    Examples
    input
    Bulbbasaur
    output
    1
    input
    F
    output
    0
    input
    aBddulbasaurrgndgbualdBdsagaurrgndbb
    output
    2
    Note
    In the first case, you could pick: Bulbbasaur.

    In the second case, there is no way to pick even a single Bulbasaur.

    In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words “Bulbasaur”.

    【题目链接】:http://codeforces.com/contest/757/problem/A

    【题解】

    统计那个字符串中出现的字母(设为集合S)出现的个数;
    出现两次(在那个字符串中)的最后(对统计后的结果)除2处理;
    然后记录S集合中出现次数最少的字母出现的次数就是答案;

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int MAXN = 1e5+10;
    
    char s[MAXN];
    map <char,int> dic;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        scanf("%s",s+1);
        int len = strlen(s+1);
        rep1(i,1,len)
            dic[s[i]]++;
        dic['u']/=2;
        dic['a']/=2;
        string s2 = "Bulbasaur";
        int mi = 21e8;
        len = s2.size();
        rep1(i,0,len-1)
            mi = min(mi,dic[s2[i]]);
        printf("%d
    ",mi);
        return 0;
    }
  • 相关阅读:
    (转)CSS3全局实现所有元素的内边距和边框不增加
    (转载)常用的Mysql数据库操作语句大全
    100天搞定机器学习|day40-42 Tensorflow Keras识别猫狗
    《统计学习方法》极简笔记P2:感知机数学推导
    100天搞定机器学习|day39 Tensorflow Keras手写数字识别
    100天搞定机器学习|day38 反向传播算法推导
    100天搞定机器学习|day37 无公式理解反向传播算法之精髓
    100天搞定机器学习|Day36用有趣的方式解释梯度下降算法
    100天搞定机器学习|Day35 深度学习之神经网络的结构
    《统计学习方法》极简笔记P4:朴素贝叶斯公式推导
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626720.html
Copyright © 2011-2022 走看看