Ural 2045 Richness of words(构造)

65 篇文章 0 订阅
9 篇文章 0 订阅

045. Richness of words

Time limit: 0.5 second
Memory limit: 64 MB
For each integer i from 1 to n, you must print a string s i of length n consisting of lowercase Latin letters.The string s i must contain exactly i distinct palindrome substrings.Two substrings are considered distinct if they are different as strings.

Input

The input contains one integer n (1 ≤ n ≤ 2000).

Output

You must print n lines. If for some i, the answer exists, print it in the form “ i :  s i” where s i is one of possible strings.Otherwise, print “ i : NO”.

Sample

inputoutput
4
1 : NO
2 : NO
3 : abca
4 : bbca


分析:四个字符abcd随便构造,n <= 2 单独处理,否则abc循环放,这样可以构造出长度为3的,长度每加1将一位换成d即可。

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXN 10005
using namespace std;
int n;
char s[MAXN];
int main()
{
	scanf("%d",&n);
	if(n == 1)
	{
		cout<<"1 : a"<<endl;
		return 0;
	}
	if(n == 2)
	{
		cout<<"1 : NO"<<endl;
		cout<<"2 : aa"<<endl;
		return 0;
	}
	cout<<"1 : NO"<<endl;
	cout<<"2 : NO"<<endl;
	for(int i = 0;i < n;i++) s[i] = 'a' + i % 3;
	s[n] = '\0';
	cout<<"3 : "<<s<<endl;
	for(int i = 4;i <= n;i++)
	{
		s[i-4] = 'd';
		cout<<i<<" : "<<s<<endl;
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值