这题写了半个小时还拉上了大佬

再写构造我是狗

1.题意简述

用\(a,e,i,o,u\)构造一个串 使串中的回文子序列最少

2.读题

这道题其实并不难,难就难在什么是"回文子序列"。看到题目的第一眼,我相信你想到的肯定是:

哦哦,这题简单,不就是让他回文部分最小吗,那我直接输出\(aeiouaeiou\)循环不就行了吗。

结果得到的结果:



你定睛一看,回文子序列()

3.解法

所以,这样怎么解呢

我们以\(n=7\)为例,以我们第一次的做法,得到的是\(aeiouae\) ,其中的回文子序列:



我们可以看到,因为一直重复,所以非常多,当数量增加时会更加明显

一种显而易见的做法,同样字母叠加到一起,构造串

仍然以\(n=7\)为例 ,以当前做法,得到的是\(aaeeiou\),其中的回文子序列



2<3,因此得证

还有一种特殊情况,那就是\(n<=5\),那就直接输出就行了

4.std

#include <bits/stdc++.h>
using namespace std;
string str(int num, string t)
{
string ret;
while (num != 0)
{
num--;
ret += t;
}
return ret;
}
void solve()
{
int n;
cin >> n;
int k = n / 5;
string ans = "";
ans += str(k, "a");
if (n % 5 != 0)
ans += 'a', n--;
ans += str(k, "e");
if (n % 5 != 0)
ans += 'e', n--;
ans += str(k, "i");
if (n % 5 != 0)
ans += 'i', n--;
ans += str(k, "o");
if (n % 5 != 0)
ans += 'o', n--;
ans += str(k, "u");
if (n % 5 != 0)
ans += 'u', n--;
cout << ans << endl;
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}

[CF题解] Simple Palindrome的更多相关文章

  1. 【题解】Palindrome pairs [Codeforces159D]

    [题解]Palindrome pairs [Codeforces159D] 传送门:\(Palindrome\) \(pairs\) \([CF159D]\) [题目描述] 给定一个长度为 \(N\) ...

  2. [LeetCode 题解]:Palindrome Number

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Determine ...

  3. leetcode题解 9. Palindrome Number

    9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...

  4. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  5. [LeetCode 题解]: Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  6. LeetCode(125)题解--Valid Palindrome

    https://leetcode.com/problems/valid-palindrome/ 题目: Given a string, determine if it is a palindrome, ...

  7. cf B. Simple Molecules

    http://codeforces.com/contest/344/problem/B #include <cstdio> #include <cstring> using n ...

  8. cf A Simple Task---线段树

    Examples Input 10 5abacdabcda7 10 05 8 11 4 03 6 07 10 1 Output cbcaaaabdd Input 10 1agjucbvdfk1 10 ...

  9. 【AtCoder】ARC095 C-F题解

    我居然每道题都能想出来 虽然不是每道题都能写对,debug了很久/facepalm C - Many Medians 排序后前N/2个数的中位数时排序后第N/2 + 1的数 其余的中位数都是排序后第N ...

  10. 【CF 675D Tree Construction】BST

    题目链接:http://codeforces.com/problemset/problem/675/D 题意:给一个由n个互异整数组成的序列a[],模拟BST的插入过程,依次输出每插入一个元素a[i] ...

随机推荐

  1. B1002 写出这个数 (20 分)

    描述 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 10 100 . 输出格式: 在 ...

  2. Friend Circles(dfs)——LeetCode进阶路

    原题链接https://leetcode.com/problems/friend-circles/ 题目描述 There are N students in a class. Some of them ...

  3. Windows系统 C/C++程序编译后首次执行时间很长 断网则正常执行 的解决方法

    Windows系统 C/C++程序编译后首次执行时间很长 断网则正常执行 的解决方法 如果您遇到此类问题,可以与我联系.我可尝试帮助您解决此问题,2SADFC4F%2$@!0$#@$%2!@#$3#! ...

  4. 薅一个ClawCloud的永久免费容器,最高可获取4核心 8G内存

    作者:故事我忘了¢ 个人微信公众号:程序猿的月光宝盒 目录 简介 看法 申请tips 简介 最近冲浪时,发现ClawCloud 推出了一个永久免费容器服务,用户最高可申请到 4 核 8G 内存的配置, ...

  5. k8s gpu共享

    k8s gpu 共享方案 1.配置环境变量实现 通过在POD的启动文件中,配置NVIDIA_VISIBLE_DEVICES的环境变量,指定显卡号.NVIDIA_VISIBLE_DEVICES可配置为具 ...

  6. helmfile使用

    说明 使用helmfile时,我们首先得了解helm的使用,以及如何开发一个helm chart. helm是kubernetes的包管理工具.在实际的使用场景中我们涉及同时部署多个chart.区分不 ...

  7. CRM item status error

    订单行项目显示状态的时候报错No status object is available for <Unknown Object>,表里也没有对应行项目的状态信息. 查了相关资料,说是用re ...

  8. @全体开发者们,ChunJun 有奖征文,精美奖品,快来参加!

    2022年4月,在 FlinkX 进行初版开源的整整四年后,技术团队决定对FlinkX进行整体升级,并更名为 ChunJun.到目前为止,ChunJun 正式更名上线已经过了一年多了.作为一款稳定.易 ...

  9. 6月23日直播预告丨如何自定义Flink LookupTable

    ​ 数栈是云原生-站式数据中台PaaS,我们在github和gitee上有一个有趣的开源项目:FlinkX,FlinkX是一个基于Flink的批流统一的数据同步工具,既可以采集静态的数据,也可以采集实 ...

  10. cmd命令行下怎么禁用和启用网络

    https://jingyan.baidu.com/article/d3b74d64b293525e76e6092a.html 执行netsh命令. interface show interface ...