时间限制: 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;
}

【枚举】Consonant Fencity @upcexam5110的更多相关文章

  1. Consonant Fencity Gym - 101612C 暴力二进制枚举 Intelligence in Perpendicularia Gym - 101612I 思维

    题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1 ...

  2. Gym 101612C Consonant Fencity

    原题传送门 题意:给定一个只含小写字母的字符串,假设aeiouyw为元音字母,现在要把一些字母变为大写,要求相同字母的大小写必须相同,统计变化后的字符串中有多少对相邻.同为辅音字母且大小写不一样的字符 ...

  3. NEERC训练实录

    听说这里可以做一些idea比较好的题.. 那就做做吧 2017-2018 ACM-ICPC, NEERC, Northern Subregional Contest A. Auxiliary Proj ...

  4. 2017-2018 ACM-ICPC, NEERC, Northern Subregional Contest

    A. Auxiliary Project 完全背包. #include<stdio.h> #include<iostream> #include<string.h> ...

  5. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  6. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)

    建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...

  7. Objective-C枚举的几种定义方式与使用

    假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...

  8. Help Hanzo (素数筛+区间枚举)

    Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000).     (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...

  9. 枚举:enum

    枚举 所谓枚举就是指定好取值范围,所有内容只能从指定范围取得. 例如,想定义一个color类,他只能有RED,GREEN,BLUE三种植. 使用简单类完成颜色固定取值问题. 1,就是说,一个类只能完成 ...

随机推荐

  1. Ansible 详解

    原文:https://www.cnblogs.com/keerya/p/7987886.html#_label0,有改动 一.Ansible简介 1.ansible是什么 a.ansible是新出现的 ...

  2. Python 事件驱动与异步IO

    一.事件驱动编程是一种编程范式,这里程序的执行流由外部事件来决定.它的特点是包含一个事件循环,当外部事件发生时使用回调机制来出发相应的处理.另外两种常见的编程范式是(单线程)同步以及多线程编程. 1. ...

  3. js将时间戳转为时间格式

    时间戳转时间格式 //分钟 let timeM= parseInt(msg/1000/60%60); if(timeM<10){ timeM="0"+timeM; } //秒 ...

  4. .netcore加入APM系统 SkyWalking

    安装环境:windows 2016 必要条件: JDK8+ Elasticsearch 5.x(注:目前不支持es6) 8080,10800,11800,12800 端口不被占用 下载skywalki ...

  5. 056 Java搭建kafka环境

    1.使用Java项目搭建 2.新目录 3.添加项目支持 4.添加mavem与scala 5.修改pom <?xml version="1.0" encoding=" ...

  6. OpenJ_Bailian 4017 爬楼梯

    时间限制: 1000 ms  空间限制: 262144 KB 题目描述 树老师爬楼梯,他可以每次走1级或者2级,输入楼梯的级数,求不同的走法数.例如:楼梯一共有3级,他可以每次都走一级,或者第一次走一 ...

  7. 异常java.lang.IllegalArgumentException:attempt to create delete event with null entity

    异常java.lang.IllegalArgumentException:attempt to create delete event with null entity解决:路径问题,前台jsp和ja ...

  8. HDU-2032解题报告

    Hdu-2032解题报告题意:实现给定行数的杨辉三角的输出. 杨辉三角的特点:每一行数据的开头和结尾是1,然后其他的数据是由其上一个数据与其左上角的数据之和组成11 11 2 11 3 3 11 4 ...

  9. gradle上传本地文件到远程maven库(nexus服务器)

    自定义aar-upload.gradle文件 artifacts { archives file('./build/outputs/aar/Lib_ads-baidu-debug.aar') } up ...

  10. 安排~~炒鸡全的JS兼容问题,码上-----【XUEBIG】

    如何处理兼容问题 如果两个都是属性,用逻辑||做兼容 如果有一个是方法,用三元做兼容 如果是多个属性或方法,封装函数做兼容 两个小知识点: 1.取消拖拽的默认行为: document.ondragst ...