zoukankan      html  css  js  c++  java
  • Codeforces Round #471 (Div. 2)B. Not simply beatiful strings


    Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide.

    You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.

    Input

    The only line contains s (1 ≤ |s| ≤ 105) consisting of lowercase latin letters.

    Output

    Print «Yes» if the string can be split according to the criteria above or «No» otherwise.

    Each letter can be printed in arbitrary case.

    Examples
    input
    ababa
    output
    Yes
    input
    zzcxx
    output
    Yes
    input
    yeee
    output
    No

    题意:如果能把一个字符串分成两份,每份都可以被分成只有相同字母的两块,并且这两块的字母不相同,那么输出yes,反之no。
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #define INF 0x3f3f3f3f
    #define lowbit(x) (x&(-x))
    #define eps 0.00000001
    #define pn printf("
    ")
    using namespace std;
    typedef long long ll;
    
    const int maxn = 1e5+7;
    map <char,int> mp;
    
    int main()
    {
        char s[maxn];
        gets(s);
        int len = strlen(s);
        for(int i=0;i<len;i++)
            mp[s[i]]++;
        int fl = 0;
        for(map<char,int>::iterator it = mp.begin(); it!=mp.end(); it++)
            if(it->second == 1)
                fl++;
        if(mp.size() > 4) printf("No
    ");
        else if(mp.size() == 2 && fl) printf("No
    ");
        else if(mp.size() == 1) printf("No
    ");
        else if(mp.size() == fl && fl%2 == 1) printf("No
    ");
        else printf("Yes
    ");
        
    }
  • 相关阅读:
    php与smarty结合应对表单get的一个小例子
    VC 使用mingw32编译ffmpeg静态库所需文件(二),mingwexsrc.cpp
    wzplayer for delphi
    wzplayer for delphi
    Delphi 调用VC生成的DLL
    VC 使用mingw32编译ffmpeg静态库所需文件(二),mingwexsrc.cpp
    VC使用mingw32编译ffmpeg静态库所需文件(一),ffmpegshim.c
    Delphi和C++数据类型对照表
    VC使用mingw32编译ffmpeg静态库所需文件(一),ffmpegshim.c
    Delphi 调用VC生成的DLL
  • 原文地址:https://www.cnblogs.com/HazelNut/p/8641666.html
Copyright © 2011-2022 走看看