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 <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
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<n;i++)
{ if((i+1)%4!=0)
s[i]='a'+(i+1)%4-1;
else
s[i]='d';
}
s[n]='\0';
puts(s);
}
return 0;
}

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

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. poj3694(动态询问割桥的数目)

    给我们一个图,然后有q次加边的操作,问每次加完边之后有多少个桥存在 首先用dfs求出所有的桥,然后dfs的过程中生成了一棵dfs树,该树有的边是桥,有的不是,用bridge[v] = true , 表 ...

  2. 《Javascript高级程序设计》读书笔记之闭包

    闭包 function createComparisonFunction(propertyName) { return function (object1, object2) { var value1 ...

  3. jQuery的理论基础

    概述 jQuery是用JavaScript语言编写的函数库,我们用时,可以直接调用jQuery中相应的函数,对于JavaScript的理解,前面的博客已经介绍过了,在这里只说一下函数的作用,也可以说为 ...

  4. 时间复杂度为O(nlogn)的LIS算法

    时间复杂度为 n*logn的LIS算法是用一个stack维护一个最长递增子序列 如果存在 x < y 且  a[x] > a[y],那么我们可以用a[y]去替换a[x] 因为a[y]比较小 ...

  5. Windows Phone开发(23):启动器与选择器之CameraCaptureTask和PhotoChooserTask

    原文:Windows Phone开发(23):启动器与选择器之CameraCaptureTask和PhotoChooserTask 这两个组件都属于选择器,而且它们也有很多相似的地方,最明显的上一点, ...

  6. 导出csv文件时,处理分隔符问题(转)

    转自:http://blog.sina.com.cn/s/blog_468530a60100kjpy.html CSV文件默认以英文逗号做为列分隔符,换行符作为行分隔符. 如果不提供网页形式只用命令行 ...

  7. java基础---->Zip压缩的使用(转)

    java中提供了对压缩格式的数据流的读写.它们封装到现成的IO 类中,以提供压缩功能.下面我们开始java中压缩文件的使用. 目录导航: 关于压缩的简要说明 GZIP压缩文件的使用 ZIP压缩文件的使 ...

  8. Javascript设计模式系列一

    定义类,方法赋值给prototype属性各种写法: 方法一: <script type="text/javascript"> ////定义Message类 var Me ...

  9. linux挂载U盘,及乱码问题解决

    1. 首先使用切换到root用户. 2. 使用fdisk -l命令查看磁盘信息,找到u盘(能够依据显示的大小确定) 3. 在/mnt下创建挂载点,比如创建usb目录:mkdir /mnt/usb 4. ...

  10. Lua之Lua数据结构-TTLSA(6)(转) good

    一. tabletable是lua唯一的数据结构.table 是 lua 中最重要的数据类型. table 类似于 python 中的字典.table 只能通过构造式来创建.其他语言提供的其他数据结构 ...