zoukankan      html  css  js  c++  java
  • codeforces518B

    Tanya and Postcard

     CodeForces - 518B 

    有个小女孩决定给他的爸爸寄明信片。她已经想好了一句话(即长度为n的字符串s),包括大写和小写英文字母。但是他不会写字,所以她决定将报纸里的字母剪下来贴到明信片上,最好能够把字符串s拼凑出来。报纸里包含字符串t,包括大写和小写英文字母。我们知道,t的长度大于或等于串s的长度。
     
    如果在s串中的某些位置上的字母能够在报纸串t中找到对应一模一样的字符,那么,她会高兴地喊“耶!”,如果在s串中的某些位置的字母只能在报纸串t中找到对应的字母(但是大小写对应不上),那么这个女孩说:“哎呦”。
     
    现在,小女孩希望她喊“耶!”越多越好。在“耶!”一样多的情况下,她说:“哎呦”要尽量多。请你帮助来计算这两个的数量。
     
    注意每个字母只能用一次。

    Input

    第一行包含串s(1≤|s| ≤2*10^ 5),由大写和小写英文字母组成。
     
    第二行包含串t(|s|≤|t| ≤2*10^ 5),包括大写和小写英文字母, 即写在报纸上的文字。
     
    这里|a| 表示字符串的长度。

    Output

    输出两个用空格隔开的非负整数:
     
    第一个数字是小姑娘说“耶!”的次数。
    第二个数字是小姑娘说“哎呦”的次数。

    Sample Input

    样例输入1:
    AbC
    DCbA
     
    样例输入2:
    ABC
    abc
     
    样例输入3:
    abacaba
    AbaCaBA

    Sample Output

     
    样例输出1:
    3 0
     
    样例输出2:
    0 3
     
    样例输出3:
    3 4
     
    sol:按题意暴力模拟,能说“耶!”就尽量说“耶!”,先做一遍说“耶!”,然后在搞另一个,O(n*2)
    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0'); return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=200005;
    int n,m;
    char S[N],T[N];
    map<char,int>Map;
    bool Used[N];
    int main()
    {
        int i,ans1=0,ans2=0;
        scanf("%s",S+1); n=strlen(S+1);
        scanf("%s",T+1); m=strlen(T+1);
        Map.clear();
        for(i=1;i<=m;i++) Map[T[i]]++;
        for(i=1;i<=n;i++) if(Map[S[i]])
        {
            ans1++;
            Used[i]=1;
            Map[S[i]]--;
        }
        for(i=1;i<=n;i++) if(!Used[i])
        {
            if(islower(S[i]))
            {
                if(Map[S[i]-'a'+'A']) {ans2++; Map[S[i]-'a'+'A']--;}
            }
            else
            {
                if(Map[S[i]-'A'+'a']) {ans2++; Map[S[i]-'A'+'a']--;}
            }
        }
        W(ans1); Wl(ans2);
        return 0;
    }
    /*
    input
    AbC
    DCbA
    output
    3 0
    
    input
    ABC
    abc
    output
    0 3
    
    input
    abacaba
    AbaCaBA
    output
    3 4
    
    input
    zzzZZZ
    ZZZzzZ
    output
    5 1
    */
    View Code
  • 相关阅读:
    poj 2187 Beauty Contest(旋转卡壳)
    poj 2540 Hotter Colder(极角计算半平面交)
    poj 1279 Art Gallery(利用极角计算半平面交)
    poj 3384 Feng Shui(半平面交的联机算法)
    poj 1151 Atlantis(矩形面积并)
    zoj 1659 Mobile Phone Coverage(矩形面积并)
    uva 10213 How Many Pieces of Land (欧拉公式计算多面体)
    uva 190 Circle Through Three Points(三点求外心)
    zoj 1280 Intersecting Lines(两直线交点)
    poj 1041 John's trip(欧拉回路)
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10590409.html
Copyright © 2011-2022 走看看