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
  1. 5
output
  1. abcda
input
  1. 3
output
  1. abc
  1. 题意: 要求生成字符串:每一个字母的出现的相邻位置之差为47.事实上仅仅须要4个字母就可以 abcdancdabcd....循环输出就可以。
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <cctype>
  6. #include <cstdlib>
  7. #include <set>
  8. #include <map>
  9. #include <vector>
  10. #include <string>
  11. #include <queue>
  12. #include <stack>
  13. #include <cmath>
  14. using namespace std;
  15. const int INF = 0x3f3f3f3f;
  16. #define LL long long
  17. char s[1000000];
  18. int main()
  19. {
  20. 	int n;
  21. 	while(~scanf("%d",&n))
  22. 	{
  23. 		for(int i=0;i<n;i++)
  24. 		{
  25. 			if((i+1)%4!=0)
  26. 				s[i]='a'+(i+1)%4-1;
  27. 			else
  28. 				s[i]='d';
  29. 		}
  30. 		s[n]='\0';
  31. 		puts(s);
  32. 	}
  33. 	return 0;
  34. }

版权声明:本文博客原创文章。博客,未经同意,不得转载。

Codeforces 110B-Lucky String(技能)的更多相关文章

  1. Lucky String

    Lucky String -- 微软笔试 标签(空格分隔): 算法 A string s is LUCKY if and only if the number of different charact ...

  2. CodeForces 146A Lucky Ticket

    Lucky Ticket Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  3. Codeforces 121A Lucky Sum

    Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...

  4. codeforces 630C Lucky Numbers

    C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...

  5. 数据结构(线段树):CodeForces 145E Lucky Queries

    E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  6. CodeForces 146E - Lucky Subsequence DP+扩展欧几里德求逆元

    题意: 一个数只含有4,7就是lucky数...现在有一串长度为n的数...问这列数有多少个长度为k子串..这些子串不含两个相同的lucky数... 子串的定义..是从这列数中选出的数..只要序号不同 ...

  7. CodeForces 797C Minimal string:贪心+模拟

    题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...

  8. 【每天一道算法题】Lucky String

    A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Gi ...

  9. Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力

    Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...

  10. Codeforces 797C - Minimal string

    C. Minimal string 题目链接:http://codeforces.com/problemset/problem/797/C time limit per test 1 second m ...

随机推荐

  1. 重新启动IIS服务的方法

    WINDOWS提供WEB服务的IIS有时候会出现訪问过大导致站点打不开,这时重新启动IIS是最好的选择. 1.界面操作 打开"控制面板"->"管理工具"- ...

  2. vps自己搭建VPN(转)

    1.购买一个VPS: https://www.pzea.com/North-America-openvz-vps.html 2.下载putty软件,进行vpn安装: http://www.chiark ...

  3. java 配置及安装Eclipse

    jdk下载 点我~ Java SE Development Kit 8u20 You must accept the Oracle Binary Code License Agreement for ...

  4. 工程PMO工作

     算起来,这是第一次以项目PMO人员的身份參与项目.尽管非常可惜没有从头參与,也没有參与到项目结束.仅仅有短短的两个月,但对项目PMO也可略窥一斑.如今就当个流水账写一写吧. 进项目组的时候,是中 ...

  5. trie + 长度优先匹配,生成串

    import com.google.common.collect.Maps; import java.util.Map; /** * tree 节点 * Created by shuly on 16- ...

  6. DB2 “The transaction log for the database is full” 存在的问题及解决方案

    DB2在执行一个大的insert/update操作的时候报"The transaction log for the database is full.. "错误,查了一下文档是DB ...

  7. 3g自己主动更新网卡驱动web完架构文档

    几年前写. 看它是否是用得上 1  简单介绍 本文档具体描写叙述了基于ASP.NET平台和IIS服务的T-Mobile自己主动更新系统的实现框架. 本文档主要从技术架构和业务架构两个方面来着手来描写叙 ...

  8. C# WinForm多线程(三)Control.Invoke

    下面我们就把在Windows Form软件中使用Invoke时的多线程要注意的问题给大家做一个介绍. 首先,什么样的操作需要考虑使用多线程?总的一条就是,负责与用户交互的线程(以下简称为UI线程)应该 ...

  9. Shell在大数据的魅力时代:从一点点思路百度大数据面试题

    供Linux开发中的同学们,Shell这可以说是一个基本功. 对于同学们的操作和维护.Shell也可以说是一种必要的技能,Shell.对于Release Team,软件配置管理的同学来说.Shell也 ...

  10. OOP思想

    OOP思想 读者朋友们大家好,我们今天这一讲就接着前面的封装继续讲解,今天就是在前面内容上面的升级,OOP思想中的继承,我们就先来解释一下继承到底是什么意思,我们在什么地方会用到继续. 继承就是,后代 ...