zoukankan      html  css  js  c++  java
  • 【枚举】Consonant Fencity @upcexam5110

    时间限制: 3 Sec 内存限制: 512 MB
    题目描述
    There are two kinds of sounds in spoken languages: vowels and consonants. Vowel is a sound, produced with an open vocal tract; and consonant is pronounced in such a way that the breath is at least partly obstructed. For example, letters a and o are used to express vowel sounds, while letters b and p are the consonants (e.g. bad, pot).
    Some letters can be used to express both vowel and consonant sounds: for example, y may be used as a vowel (e.g. silly) or as a consonant (e.g. yellow). The letter w, usually used as a consonant (e.g. wet) could produce a vowel after another vowel (e.g. growth) in English, and in some languages (e.g. Welsh) it could be even the only vowel in a word.
    In this task, we consider y and w as vowels, so there are seven vowels in English alphabet: a, e, i, o, u, w and y, all other letters are consonants.
    Let’s define the consonant fencity of a string as the number of pairs of consecutive letters in the string which both are consonants and have different cases (lowercase letter followed by uppercase or vice versa). For example, the consonant fencity of a string CoNsoNaNts is 2, the consonant fencity of a string dEsTrUcTiOn is 3 and the consonant fencity of string StRenGtH is 5.
    You will be given a string consisting of lowercase English letters. Your task is to change the case of some letters in such a way that all equal letters will be of the same case (that means, no letter can occur in resulting string as both lowercase and uppercase), and the consonant fencity of resulting string is maximal.
    输入
    The only line of the input contains non-empty original string consisting of no more than 106 lowercase English letters.
    输出
    Output the only line: the input string changed to have maximum consonant fencity.
    样例输入
    consonants
    样例输出
    coNsoNaNts

    把26个字母分成19个辅音字母和7个元音字母,让你通过改变辅音字母的大小写状态,使得字符串中连续的两个大小写状态不同的辅音字母组成的字母对数量最多,输出该状态下的字符串。
    扫一遍字符串,统计每种辅音字母对的数量,总共19*19种。
    枚举19个辅音字母的大小写状态(二进制状压),内循环枚举每两个辅音字母的前后关系,维护一个最大值
    复杂度 o(219192)(219∗192)

    #define IN_LB() freopen("F:\in.txt","r",stdin)
    #define IN_PC() freopen("C:\Users\hz\Desktop\in.txt","r",stdin)
    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    
    int comb[20][20];
    int mapp[] = {0,1,2,3,0,4,5,6,0,7,8,9,10,11,0,12,13,14,15,16,0,17,0,18,0,19};
    char s[1000005];
    
    void out(int sta) {
        for(int i=0; s[i]; i++) {
            if(sta&(1<<(mapp[s[i]-'a']-1))) {
                printf("%c",s[i]-'a'+'A');
            }
            else printf("%c",s[i]);
        }
        printf("
    ");
    }
    
    int main() {
    //    IN_LB();
        scanf("%s",s);
        for(int i=1; s[i]; i++) {
            comb[mapp[s[i-1]-'a']][mapp[s[i]-'a']]++;
        }
        int ans = 0,maxn = 0,sum = 1<<19;
        for(int i=0; i<sum; i++) {
            int cnt = 0;
            for(int j=1; j<=19; j++) {
                for(int k=1; k<=19; k++) {
                    if( (i&(1<<(j-1))&&!(i&(1<<(k-1)))) || ((!(i&(1<<(j-1))))&&(i&(1<<(k-1)))) ) {
                        cnt += comb[j][k];
                    }
                }
            }
            if(cnt>maxn) {
                maxn = cnt;
                ans = i;
            }
        }
        out(ans);
        return 0;
    }
    
  • 相关阅读:
    libtorch初体验
    libtorch 常用api函数示例(史上最全、最详细)
    VS2015,vs2019用正则表达式搜索删除空白行的方法
    CMake引入opencv3.1.0编译时includes non-existent path问题解决
    opencv编译的时候的注意事项------如果出现 target glog::glog 找不到的情况,可能是由于glog的版本过低导致的。通常与ceres有关
    ID3D11Multithread 未声明的标识符 opencv 411 opencv400 3411 opencv440 vs2015 都出现这个错误 但是opencv311没有出现这个问题
    错误 LNK2001 无法解析的外部符号 "__declspec(dllimport) bool cv::__termination" (__imp_?__termination@cv@@3_NA) opencv_cudev
    raw.githubusercontent.com无法连接
    编译opencv3.1.0时出现错误:error: ‘NppiGraphcutState’ has not been declared
    Ubuntu16.04 安装g++6
  • 原文地址:https://www.cnblogs.com/NeilThang/p/9356613.html
Copyright © 2011-2022 走看看