题面

题意:如果一个字符串的最小表示法是他自己,他就是一个Lyndon Word.

例如  aabcb 他的循环串有 abcba  bcbaa cbaab baabc 其中字典序最小的是他自己

现在给你n,m表示用前m个字符(从a开始),拼成长度不超过n的字符串中,输出字典序排列的的  l->r 的串

l<=r<=1e7   r-l<=1e5

题解:我们根据样例 n=4 m=3可以看出,一共32个:a, aaab, aaac, aab, aabb, aabc, aac, aacb, aacc,

ab, abac, abb,abbb, abbc, abc, abcb, abcc, ac, acb, acbb, acbc, acc, accb, accc,

b, bbbc, bbc,bbcc, bc, bcc, bccc, c.

不难看出,我们每次从a开始,写到长度n,然后会后退1位,从b开始,继续写到长度n,又退回一位写c,

退一位的完了,就继续退两位.

于是模拟这个过程输出就好了. 每一次复杂度就是O(26*r)的

 #include<bits/stdc++.h>
using namespace std;
int T,n,m,l,r;
char s[];
int main()
{
while (scanf("%d%d%d%d",&n,&m,&l,&r)!=EOF)
{
T++;
printf("Case %d:\n",T);
s[]='a';
int i=,tot=;
while (i<r)
{
i++;
if (i>=l)
{
for (int k=;k<tot;k++) printf("%c",s[k]);
printf("\n");
}
int x=tot;
while (tot<n)
{
s[tot]=s[tot%x];
tot++;
}
while (tot>) if (s[tot-]-'a'+==m) tot--;else break;
s[tot-]=char(s[tot-]+);
}
}
}

最新文章

  1. mysql重点--索引
  2. python实现查找指定文件
  3. oracle 11g 表空间使用率
  4. iOS开发——OC篇&amp;特殊数据类型
  5. mysql 数据库字符串替换
  6. java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.util.JSONUtils
  7. 免费UI框架推荐--Charisma UI
  8. YYKit笔记之FPS
  9. Android :android.os.Process.myTid()与 Thread.currentThread().getId();
  10. JsonCpp(C++程序使用)
  11. 【MFC】基于OpenCV的魔镜
  12. Linux下MongoDB安装和配置详解
  13. 判断语句之单if
  14. 7.mongo python 库 pymongo的安装
  15. lfs(systemd版本)学习笔记-第2页
  16. NSIS Error:Error writing temporary file. Make sure your temp folder is valid的解决办法
  17. Tesseract-OCR 3.05 多过语言文字识别(运行程序+中英日韩语言包)
  18. Use Reentrant Functions for Safer Signal Handling(译:使用可重入函数进行更安全的信号处理)
  19. Kafka记录Nginx的POST请求
  20. [转帖]SSD的工作原理、GC和TRIM、写入放大以及性能评测

热门文章

  1. ZOJ - 3993 - Safest Buildings (数学)
  2. 如何在 CentOS 7 上安装 Nginx
  3. db2记录去重
  4. 一篇入门MongoDB
  5. webpack3 + vue 添加 serviceWorker
  6. 洛谷 2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
  7. L2-012. 关于堆的判断(STL中heap)
  8. 【Codeforces 466B】Wonder Room
  9. mybatis写当天 当月的数据 时间段数据https://www.cnblogs.com/xzjf/p/7600533.html
  10. 《Noisy Activation Function》噪声激活函数(一)