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. Android---53---多线程下载

    采用HttpURLConnection HttpURLConnection从继承URLConnection,它也可以被用来发送到指定的网站GET求 POST求. 办法: int getResponse ...

  2. Linux 安装之U盘引导

    说到装系统最简单的方法无非就是找个系统安装光盘来然后就一步一步慢慢的安装.简单是简单但好似大多数人好像都木有Linux的安装光盘. 因此仅仅能用U盘来模拟光盘的功能来装系统咯. 电脑上装有Window ...

  3. aStar算法求第k短路

    A*的概念主意在于估计函数,f(n)=g(n)+h(n),f(n)是估计函数,g(n)是n节点的当前代价,h(n)是n节点的估计代价:而实际中,存在最优的估计函数f'(n)=g'(n)+h'(n),那 ...

  4. QTP脚本--应用参数化来测试某个输入框

    以前一直觉得自己没有写代码的资质,太急于求成,以为一天就能写好几个功能,几千行代码,于是就没耐心了,没心情学下去了....但是最近发现其实写代码是一个漫长的过程,都是在修修改改中成长起来的.于是今天试 ...

  5. 局域网连接SQL Server数据库配置

    首先要保证两台机器位于同一局域网内,然后打开配置工具→SQL Server配置管理器进行配置.将MSSQLSERVER的协议的TCP/IP的(IP1.IP2)TCPport改为1433,已启用改为是. ...

  6. AutoFac使用方法总结:Part I

    注册部分 使用RegisterType进行注册 [Fact] public void can_resolve_myclass() { var builder = new ContainerBuilde ...

  7. Linux 下开启ssh服务(转)

    二.SSH SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立在应用层和传输层基础上的安全协议.SSH 是目 ...

  8. 修改系统环境变量 cmd命令

    详细大家对cmd的使用都有了一些简单的了解,但是困扰大家的主要的问题就是: cmd命令修改环境变量有两种方式:1. 短期内有效,在关闭dos窗口后就自动失效 2.长期有效,关闭dos窗口后还有效 下面 ...

  9. 02、Unicode 汉子转码小工具

    原文:02.Unicode 汉子转码小工具 在做 Windows app 的时候,与服务器端交互使用的是 json 格式的数据,里面的汉字内容被 编码成 unicode 格式,在调试的时候不太方便,就 ...

  10. 更改Activity的最底层的布局

    public void attachToActivity(Activity activity) { mActivity = activity; TypedArray a = activity.getT ...