【枚举】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;
}
【枚举】Consonant Fencity @upcexam5110的更多相关文章
- Consonant Fencity Gym - 101612C 暴力二进制枚举 Intelligence in Perpendicularia Gym - 101612I 思维
题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1 ...
- Gym 101612C Consonant Fencity
原题传送门 题意:给定一个只含小写字母的字符串,假设aeiouyw为元音字母,现在要把一些字母变为大写,要求相同字母的大小写必须相同,统计变化后的字符串中有多少对相邻.同为辅音字母且大小写不一样的字符 ...
- NEERC训练实录
听说这里可以做一些idea比较好的题.. 那就做做吧 2017-2018 ACM-ICPC, NEERC, Northern Subregional Contest A. Auxiliary Proj ...
- 2017-2018 ACM-ICPC, NEERC, Northern Subregional Contest
A. Auxiliary Project 完全背包. #include<stdio.h> #include<iostream> #include<string.h> ...
- Swift enum(枚举)使用范例
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)
建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...
- Objective-C枚举的几种定义方式与使用
假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- 枚举:enum
枚举 所谓枚举就是指定好取值范围,所有内容只能从指定范围取得. 例如,想定义一个color类,他只能有RED,GREEN,BLUE三种植. 使用简单类完成颜色固定取值问题. 1,就是说,一个类只能完成 ...
随机推荐
- C# 之 比较两个word文档的内容
利用 Microsoft.Office.Interop.Word 组件进行比较.引入命名空间:using Word2013 = Microsoft.Office.Interop.Word; 代码如下: ...
- angularjs 中通过 $location 进行路由跳转传参
$location.path('/page1').search({id: $scope.id,name:$scope.name}); 带参数跳转页面,在新的页面通过$routeParams接收参数 $ ...
- react添加样式的四种方法
React给添加元素增加样式 第一种方法: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- java项目打包生成MD5文件
之所以发出这篇博客,因为我前几天搞这个问题搞了几天,各种百度居然都没有找到相关的案例,虽然很简单的事件.可是百度博客上面居然都搜不到案例o(* ̄︶ ̄*)o觉得奇怪!!! 新总监来了,项目要上线,以前都 ...
- VS2017 cdkey
Enterprise:NJVYC-BMHX2-G77MM-4XJMR-6Q8QF ProfessionalKBJFW-NXHK6-W4WJM-CRMQB-G3CDH
- 060 SparkStream 的wordcount示例
1.SparkStream 入口:StreamingContext 抽象:DStream 2.SparkStreaming内部原理 当一个批次到达的时候,会产生一个rdd,这个rdd的数据就是这个批次 ...
- rest模式get,post,put,delete简单讲解
1.请求方法为get时,会向数据库请求数据,类似于select语言,只能达到查询的效果,不会添加,修改,不会影响资源的内容,无副作用 2.请求方法为post时,该方法,用于向服务器添加数据,可以改变数 ...
- Idea中lombok不生效原因
我们可以通过在maven中插入配置信息 <dependency> <groupId>org.projectlombok</groupId> <artifact ...
- ♣eclipse护眼颜色和关键字颜色设置
eclipse护眼颜色和字体大小设置 ♣eclipse护眼颜色和关键字颜色设置 ♣eclipse字体大小设置(包括jsp , .xml ,.java) 1.Eclipse字体大小调整: 窗口(Wi ...
- 比特币源码分析--C++11和boost库的应用
比特币源码分析--C++11和boost库的应用 我们先停下探索比特币源码的步伐,来分析一下C++11和boost库在比特币源码中的应用.比特币是一个纯C++编写的项目,用到了C++11和bo ...