Codeforces 110B-Lucky String(技能)
2 seconds
256 megabytes
standard input
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.
The single line contains a positive integer n (1 ≤ n ≤ 105)
— the length of the sought string.
Print on the single line the lexicographically minimal lucky string whose length equals n.
5
abcda
3
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(技能)的更多相关文章
- Lucky String
Lucky String -- 微软笔试 标签(空格分隔): 算法 A string s is LUCKY if and only if the number of different charact ...
- CodeForces 146A Lucky Ticket
Lucky Ticket Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- Codeforces 121A Lucky Sum
Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...
- codeforces 630C Lucky Numbers
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...
- 数据结构(线段树):CodeForces 145E Lucky Queries
E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- CodeForces 146E - Lucky Subsequence DP+扩展欧几里德求逆元
题意: 一个数只含有4,7就是lucky数...现在有一串长度为n的数...问这列数有多少个长度为k子串..这些子串不含两个相同的lucky数... 子串的定义..是从这列数中选出的数..只要序号不同 ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
- 【每天一道算法题】Lucky String
A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Gi ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
- Codeforces 797C - Minimal string
C. Minimal string 题目链接:http://codeforces.com/problemset/problem/797/C time limit per test 1 second m ...
随机推荐
- Ansj配置指南!
=.= 折腾死 ①你想要http://maven.ansj.org/org/ansj/ansj_seg/找一个尽可能高的版本号,比方2.0.7,点进去之后找到相应的jar,比方ansj_seg-2.0 ...
- WPF对于xml的简单操作(下)绑定ListView
上个月做好的,电脑给盗了,没及时存在网盘,也及时发到随笔,于是乎悲哉!搞了一个上午终于绑定好了,有时候就是这么眼瞎,Path和XPath全瞎了,摸滚了一个上午,赶紧的随笔跟上先. <ListVi ...
- 使用gSoap规避和改动ONVIF标准类型结构的解析
ONVIF/gSoap依赖关系及问题 ONVIF是一组服务规范,标准參考 gSoap是一套基于实现SOAP通信接口的工具链 即是,当我们须要訪问ONVIF的Web Service或实现对ONVIF部分 ...
- HDU 3036 Escape 网格图多人逃生 网络流||二分匹配 建图技巧
题意: 每一个' . '有一个姑娘, E是出口,'.'是空地 , 'X' 是墙. 每秒钟每一个姑娘能够走一步(上下左右) 每秒钟每一个出口仅仅能出去一个人 给定n*m的地图, 时限T 问全部姑娘是否能 ...
- HOJ2275 Number sequence
Number sequence My Tags tag=&type=or" style="margin:0px; padding:0px; color:rgb(27,87, ...
- 比較Swift与HDFS话Ceph本质(by quqi99)
作者:张华 发表于:2014-06-21版权声明:能够随意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 (http://blog.csdn.net/quqi99 ) 作者将又 ...
- 尝到awk
我前几天写的sed,这个时候继续了解它的兄弟,awk,两者都使用,一种感觉.既可以用来处理场.假设你想要做文本处理.sed删除.匹配,一些频繁更换使用,假设每一行文本,你想深入,一些每行和列处理的,例 ...
- TCP/IP详细说明--滑模、拥塞窗口、慢启动、Negle算法
TCP的数据流大致能够分为两类,交互数据流与成块的数据流. 交互数据流就是发送控制命令的数据流.比方relogin,telnet.ftp命令等等.成块数据流是用来发送数据的包,网络上大部分的TCP包都 ...
- web网站架构
浅谈web网站架构演变过程 前言 我们以javaweb为例,来搭建一个简单的电商系统,看看这个系统可以如何一步步演变. 该系统具备的功能: 用户模块:用户注册和管理 商品模块:商品展示和管 ...
- Memento pattern
21.5 再谈备忘录的封装 备忘录是一个很特殊的对象,只有原发器对它拥有控制的权力,负责人只负责管理,而其他类无法访问到备忘录,因此我们需要对备忘录进行封装. 为了实现对备忘录对象的封装,需要对备忘录 ...