题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2045


题意:给一个数n,对于每一个i∈[1,n],输出一个长度为n的字符串si,且si里面含有i个不同的回文子串。如果有输出si,否则输出NO。字符串仅由26个小写字母组成。


思路:这是一个构造题,其实我们可以这么构造abcde.....,每一个字母就是一个不同的回文子串,然后凑够i个就回到a再循环至指定长度即可。那么现在还有一个问题,如果不同的回文子串大于26怎么办,我们只有26个不同的英文字母,仔细想想,n个连续的a含有的不同的回文子串个数不就是n吗(1个a,2个a,...n个a)所以我们在前面补足a即可。


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <utility>
using namespace std;
#define rep(i,j,k) for (int i=j;i<=k;i++)
#define Rrep(i,j,k) for (int i=j;i>=k;i--)int n;int main()
{cin>>n;if ( n == 1 ){puts("1 : a");}else if ( n == 2 ){puts("1 : NO");puts("2 : ab");}else{rep(i,1,n)if ( i <= 2 )printf("%d : NO\n",i);else{printf("%d : ",i);int t = 0;int mod = min(26,i);int len = n;if ( i > 26 ){rep(j,1,i-26) putchar('a');len-=(i-26);}rep(j,1,len){putchar('a'+t);t = (t+1) % mod;}putchar('\n');}}return 0;
}


Ural 2045 Richness of words相关推荐

  1. Ural 2045. Richness of words 打表找规律

    2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...

  2. URAL 2045 Richness of words (回文子串,贪心)

    Richness of words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/J Description For each ...

  3. URAL 2037 Richness of binary words (回文子串,找规律)

    Richness of binary words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/B Description Fo ...

  4. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

  5. Timus Online Judge 2045 Richness of words

    今天下午组队训练,做完整的套题.这是今天下午唯一AC的题目,也是这套题目中最简单的题目,顿时就不开心了. 题目链接:http://acm.timus.ru/problemset.aspx?space= ...

  6. Ural 2037. Richness of binary words (打表+构造)

    Description For each integer i from 1 to n, you must print a string si of length n consisting of let ...

  7. Ural 1018 (树形DP+背包+优化)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 题目大意:树枝上间连接着一坨坨苹果(不要在意'坨'),给 ...

  8. bzoj1814 Ural 1519 Formula 1(插头dp模板题)

    1814: Ural 1519 Formula 1 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 924  Solved: 351 [Submit][S ...

  9. URAL 1635 Mnemonics and Palindromes

    URAL 1635 思路:区间dp+贪心,先n^2处理出每段区间是否是回文串,然后贪心地找每一段1到i的最少分割. 代码: #include<bits/stdc++.h> using na ...

最新文章

  1. 深度学习(九)——花式卷积
  2. 二叉树的前中后序查找+思路分析
  3. 一个卖了1300的Java程序引发的深思
  4. python中tolist()功能
  5. Oracle从入门到精通
  6. IDEA集成有道翻译插件/maven帮助插件/mybatis插件
  7. 基于SSM的课设管理小程序源码(课程设计源码)
  8. mina框架CumulativeProtocolDecoder.doDecode方法浅析
  9. [Python GUI]Python内置图形界面tkinter Eye-Hand Coordination--游戏实战1
  10. JS 设置适配屏幕分辨率大小
  11. 布尔逻辑代数化简公式
  12. 接着奏乐接着舞 Matlab制作圣诞树和圣诞快乐歌
  13. 一个基于css的简单悬浮按钮
  14. 我是如何用一行代码表白学妹~❤520情人节送女朋友的3D樱花雨相册礼物❤~(程序员表白专属)...
  15. 什么是搜索引擎蜘蛛机器人?是如何工作的
  16. Havok和Physx对比
  17. 2 为什么软件架构很重要
  18. 如果计算机电源突然断电 会导致,电脑突然断电问题
  19. 智力题_环回到原点问题
  20. 关于服务器维修的报告模板,维修报告(模板).doc

热门文章

  1. PHP interface 接口继承(一丶单接口继承)
  2. 深入探究知道创宇主动防御体系:云蜜罐因何诞生?
  3. 《简单的逻辑学》阅读笔记(思维导图)
  4. 未来广告机面临的问题
  5. 我的世界服务器修改id指令,我的世界指令怎么用,我的世界附魔指令id
  6. Windows下查看Android手机APP日志
  7. Charles服务器代理使用
  8. 计算机网络自顶向下方法(二)——应用层
  9. 编码——隐匿在计算机软硬件背后的语言上
  10. Cheapest Flights Within K Stops