zoukankan      html  css  js  c++  java
  • CodeForces

    B. Not simply beatiful strings
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    题目链接:http://codeforces.com/problemset/problem/955/B

    题目大意:读不懂题的苦。。。美丽的字符串的标准是:能分成两部分,分成的两部分由同一个字母组成。比如aaabb就是美丽的,分成aaa与bb,ax也是美丽的,a与x。 而让我们输出yes的字符串并不是 “字符串是不是美丽”的,输出yes的条件是这个字符串可以分成两部分,这两部分都是美丽的,然后输出yes。

    比如说aaabb输出yes,分成美丽的两部分ab与aab; 而zzcxx输出yes分成两个美丽的两个部分zc与zxx。 而accc输出No,因为只能分成a与ccc(都不是美丽的字符串) 或者分ac与cc(ac是美丽的字符,而cc不是,因为cc分成两部分为c与c,是相同的)

    AC代码:

    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<iostream>
    #include<cstdlib>
    #include<string>
    using namespace std;
    const int MaxN = 1e5 + 5;
    char a[MaxN];
    int id[5];
    
    int main()
    {
        int num = 1;
        cin >> a;
        int len = strlen(a);
        if(len < 4) printf("No
    ");
        else {
            sort(a, a + len);
            for(int i = 1; i < len; i++) {
                if(a[i] != a[i-1]) {
                    id[num] = i;
                    num++;
                }
                if(num > 4) {
                    printf("No
    ");
                    break;
                }
            }
            if(num == 1) printf("No
    ");
            else if(num == 2) {
                if(id[1] >= 2 && len - id[1] >= 2 ) printf("Yes
    ");
                else printf("No
    ");
            }
            else if( num == 3){
                if(id[1] == 1 && fabs(id[2] - id[1]) == 1 && len - id[2] == 1) 
                    printf("No
    ");
                else printf("Yes
    ");
            }
            else if(num == 4) {
                printf("Yes
    ");
            }
        }
    }
     
  • 相关阅读:
    POJ1769 Minimizing maximizer(DP + 线段树)
    ZOJ3201 Tree of Tree(树形DP)
    POJ3613 Cow Relays(矩阵快速幂)
    POJ3635 Full Tank?(DP + Dijkstra)
    ZOJ3195 Design the city(LCA)
    POJ3368 Frequent values(RMQ线段树)
    POJ3686 The Windy's(最小费用最大流)
    HDU4871 Shortest-path tree(最短路径树 + 树的点分治)
    POJ3013 Big Christmas Tree(最短路径树)
    Gym100685G Gadget Hackwrench(倍增LCA)
  • 原文地址:https://www.cnblogs.com/smuzoey/p/11787452.html
Copyright © 2011-2022 走看看