题目如下:
Numerology is a science that is used by many people to findout a mans personality, sole purpose of life, desires to experience etc. Somecalculations of numerology are very complex, while others are quite simple. Youcan sit alone at home and do these easy calculations without taking any oneshelp. However in this problem you wont be asked to find the value of yourname.
To find the value of a name modern numerologists have assigned values to all theletters of English Alphabet. The table on the left shows the numerical valuesof all letters of English alphabets. Five letters A, E, I, O, U are vowels. Restsof the letters are consonant.In this table all letters in column 1 have value 1, allletters in column 2 have value 2 and so on. So T has value 2, F has value 6, Rhas value 9, O has value 6 etc. When calculating the value of a particular namethe consonants and vowels are calculated separately. The following pictureexplains this method using the name ``CHRISTOPHER RORY PAGE". So you can see that to find the consonant value, the values of individualconsonants are added and to find the vowel value the values of individualvowels are added.A mad Numerologist suggests people many strange lucky names.He follows the rules stated below while giving lucky names.3 1 5 5
Case 1: A Case 2: AJAJA Case 3: AJAJA
本题看似高端,其实是道比较水的题,要求名字中的元音字母对应的数字之和最小和辅音字母对应的数字之和最小,并且在此条件下,该名字还应是字典序最小。思路是把元音字母和辅音字母与数字的对应用两个数组实现(只需要实现顺序即可并不需要知道具体对应的数字,因为只需要输出满足和最小的名字而不需要输出和),因为每个元音字母最多出现21次,而辅音最多出现5次,所以应对应时设置21个相同字母和5个相同字母,对名字数组中的每个位置,若是奇数,遍历元音数组,反之遍历辅音数组。这样就能满足和最小。再对得到的名字分别对元音和辅音排序,使之满足字典序最小。刚开始误认为只要遍历了数组,就一定是字典序最小,WA了,后来发现交换字母的顺序和不变但可以使字典序更小。
AC的代码如下:
UVA The Mad Numerologist,布布扣,bubuko.com
原文:http://blog.csdn.net/u013840081/article/details/24133009