设为首页 加入收藏

TOP

Codeforces 110B-Lucky String(技巧)
2015-07-20 17:29:54 来源: 作者: 【 】 浏览:3
Tags:Codeforces 110B-Lucky String 技巧
B. Lucky String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

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.

    Input

    The single line contains a positive integer n (1?≤?n?≤?105) ― the length of the sought string.

    Output

    Print on the single line the lexicographically minimal lucky string whose length equals n.

    Sample test(s) input
    5
    
    output
    abcda
    
    input
    3
    
    output
    abc
    题意: 要求生成字符串:每个字母的出现的相邻位置之差为4或7.其实只需要4个字母即可 abcdancdabcd....循环输出即可。
    #include 
         
          
    #include 
          
            #include 
           
             #include 
            
              #include 
             
               #include 
              
                #include 
               
                 #include 
                 #include 
                 
                   #include 
                  
                    #include 
                   
                     #include 
                    
                      #include 
                     
                       using namespace std; const int INF = 0x3f3f3f3f; #define LL long long char s[1000000]; int main() { int n; while(~scanf("%d",&n)) { for(int i=0;i
                      
                       

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇设计模式的C++实现 1.单例模式 下一篇zoj 3288 Domination (概率dp)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Linux_百度百科 (2025-12-26 12:51:52)
·Shell 流程控制 | 菜 (2025-12-26 12:51:49)
·TCP/UDP协议_百度百科 (2025-12-26 12:20:11)
·什么是TCP和UDP协议 (2025-12-26 12:20:09)
·TCP和UDP详解 (非常 (2025-12-26 12:20:06)