【枚举】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(219∗192)(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("\n");
} 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;
}
上一篇:『.NET Core CLI工具文档』(七)dotnet-new


下一篇:『.NET Core CLI工具文档』(十一)dotnet-test