Ural 2045 Richness of words
题目链接: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相关推荐
- Ural 2045. Richness of words 打表找规律
2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...
- URAL 2045 Richness of words (回文子串,贪心)
Richness of words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/J Description For each ...
- URAL 2037 Richness of binary words (回文子串,找规律)
Richness of binary words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/B Description Fo ...
- Ural 2037. Richness of binary words 打表找规律 构造
2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...
- Timus Online Judge 2045 Richness of words
今天下午组队训练,做完整的套题.这是今天下午唯一AC的题目,也是这套题目中最简单的题目,顿时就不开心了. 题目链接:http://acm.timus.ru/problemset.aspx?space= ...
- 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 ...
- Ural 1018 (树形DP+背包+优化)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 题目大意:树枝上间连接着一坨坨苹果(不要在意'坨'),给 ...
- 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 ...
- URAL 1635 Mnemonics and Palindromes
URAL 1635 思路:区间dp+贪心,先n^2处理出每段区间是否是回文串,然后贪心地找每一段1到i的最少分割. 代码: #include<bits/stdc++.h> using na ...
最新文章
- 深度学习(九)——花式卷积
- 二叉树的前中后序查找+思路分析
- 一个卖了1300的Java程序引发的深思
- python中tolist()功能
- Oracle从入门到精通
- IDEA集成有道翻译插件/maven帮助插件/mybatis插件
- 基于SSM的课设管理小程序源码(课程设计源码)
- mina框架CumulativeProtocolDecoder.doDecode方法浅析
- [Python GUI]Python内置图形界面tkinter Eye-Hand Coordination--游戏实战1
- JS 设置适配屏幕分辨率大小
- 布尔逻辑代数化简公式
- 接着奏乐接着舞 Matlab制作圣诞树和圣诞快乐歌
- 一个基于css的简单悬浮按钮
- 我是如何用一行代码表白学妹~❤520情人节送女朋友的3D樱花雨相册礼物❤~(程序员表白专属)...
- 什么是搜索引擎蜘蛛机器人?是如何工作的
- Havok和Physx对比
- 2 为什么软件架构很重要
- 如果计算机电源突然断电 会导致,电脑突然断电问题
- 智力题_环回到原点问题
- 关于服务器维修的报告模板,维修报告(模板).doc