CF110B.Lucky String
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number.
For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are:
- b: 2
- c: 3, 10
- d: 4, 8
- e: 6
- f: 7
- z: 1, 5, 9
- Lists of positions of letters a, g, h, ..., y are empty.
This string is lucky as all differences are lucky numbers. For letters z: 5 - 1 = 4, 9 - 5 = 4, for letters c: 10 - 3 = 7, for letters d: 8 - 4 = 4.
Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.
Find the lexicographically minimal lucky string whose length equals n.
佩佳喜欢幸运数字。众所周知,幸运数字是指十进制表示中仅包含幸运数字 4 和 7 的正整数。例如,47、744、4 是幸运数字,而 5、17、467 不是。
佩佳最近学会了判断一个由小写拉丁字母组成的字符串是否为幸运字符串。对每个单独的字母,将其在字符串中所有出现位置按升序列出。这样会得到 26 个数字列表(对应字母 a–z),其中某些列表可能为空。当且仅当每个列表中任意两个相邻数字的绝对差值均为幸运数字时,该字符串才被视为幸运字符串。
例如,考虑字符串 "zbcdzefdzc"。各相同字母的位置列表如下:
- b: 2
- c: 3, 10
- d: 4, 8
- e: 6
- f: 7
- z: 1, 5, 9
- 字母 a、g、h、…、y 的位置列表均为空。
该字符串是幸运的,因为所有相邻差值均为幸运数字:对于字母 z,有 5 − 1 = 4、9 − 5 = 4;对于字母 c,有 10 − 3 = 7;对于字母 d,有 8 − 4 = 4。
注意:若某个字母在字符串中仅出现一次,则其对应的位置列表长度为 1,不产生任何相邻差值,因此不影响字符串的幸运性。所有字母互不相同的字符串也被视为幸运字符串。
请找出长度恰好为 n 的字典序最小的幸运字符串。
输入格式
The single line contains a positive integer n (1 ≤ n ≤ 105) — the length of the sought string.
单行包含一个正整数 n(1≤n≤105)——即所求字符串的长度。
输出格式
Print on the single line the lexicographically minimal lucky string whose length equals n.
在单行上输出长度为 n 的字典序最小的幸运字符串。
输入输出样例
输入#1
5
输出#1
abcda
输入#2
3
输出#2
abc
说明/提示
The lexical comparison of strings is performed by the < operator in modern programming languages. String a is lexicographically less than string b if exists such i (1 ≤ i ≤ n), that a__i < b__i, and for any j (1 ≤ j < i) a__j = b__j.
现代编程语言中,字符串的字典序比较通过 < 运算符实现。字符串 a 在字典序上小于字符串 b,当且仅当存在某个下标 i(满足 1 ≤ i ≤ n),使得 ai < bi,且对任意 j(满足 1 ≤ j < i)均有 aj = bj。
输入解题思路,AI测评打分。不知道怎么写?