当前位置:网站首页>C. Palindromifier
C. Palindromifier
2022-08-08 16:37:00 【秦小咩】
C. Palindromifier
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Ringo found a string ss of length nn in his yellow submarine. The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the string ss into a palindrome by applying two types of operations to the string.
The first operation allows him to choose ii (2≤i≤n−12≤i≤n−1) and to append the substring s2s3…sis2s3…si (i−1i−1 characters) reversed to the front of ss.
The second operation allows him to choose ii (2≤i≤n−12≤i≤n−1) and to append the substring sisi+1…sn−1sisi+1…sn−1 (n−in−i characters) reversed to the end of ss.
Note that characters in the string in this problem are indexed from 11.
For example suppose s=s=abcdef. If he performs the first operation with i=3i=3 then he appends cb to the front of ss and the result will be cbabcdef. Performing the second operation on the resulted string with i=5i=5 will yield cbabcdefedc.
Your task is to help Ringo make the entire string a palindrome by applying any of the two operations (in total) at most 3030 times. The length of the resulting palindrome must not exceed 106106
It is guaranteed that under these constraints there always is a solution. Also note you do not have to minimize neither the number of operations applied, nor the length of the resulting string, but they have to fit into the constraints.
Input
The only line contains the string SS (3≤|s|≤1053≤|s|≤105) of lowercase letters from the English alphabet.
Output
The first line should contain kk (0≤k≤300≤k≤30) — the number of operations performed.
Each of the following kk lines should describe an operation in form L i or R i. LL represents the first operation, RR represents the second operation, ii represents the index chosen.
The length of the resulting palindrome must not exceed 106106.
Examples
input
Copy
abac
output
Copy
2 R 2 R 5
input
Copy
acccc
output
Copy
2 L 4 L 2
input
Copy
hannah
output
Copy
0
Note
For the first example the following operations are performed:
abac →→ abacab →→ abacaba
The second sample performs the following operations: acccc →→ cccacccc →→ ccccacccc
The third example is already a palindrome so no operations are required.
=========================================================================
一般此类题目都是有很简单的通解的,而且大都根据题目给出的限定次数推测可能的方案。但是本题用30次来故意误导选手,其实只需要三次,就能完成全部的构造
不难发现,只进行一次操作1,2就能把我们的字符串变成非常类似回文串的形式。例如操作2
abcd
对2进行操作2
abcd-> abcd cb
可以看出除了a,剩下的就是回文了
而我们进行操作1,2都无法对位置1进行修改,所以我们应该在本次2操作之前对字符串进行一些操作
按照1,2,1的顺序来即可。
#include<iostream>
# include<algorithm>
# include<unordered_map>
using namespace std;
typedef long long int ll;
int main ()
{
string s;
cin>>s;
int n=s.length();
cout<<3<<endl;
cout<<'L'<<" "<<2<<endl;
cout<<'R'<<" "<<2<<endl;
cout<<'R'<<" "<<2*n-1<<endl;
return 0;
}
abcd -> b abcd - > b abc d cba -> b abc d cba b
边栏推荐
猜你喜欢
4、S32K14X学习笔记:S32 Design Studio 新建和导入工程
APICloud AVM wraps date and time selection components
赶紧进来修内功!!!带你认识C语言中各种进制数和原码反码补码.
VIT:Transformer进军CV的里程碑
VISTA无人驾驶模拟器;FinRL量化金融深度强化学习库;『深度神经网络应用』电子书;CUDA/TensorRT案例集锦;前沿论文 | ShowMeAI资讯日报
字节一面:TCP 和 UDP 可以使用同一个端口吗?
GPT3中文自动生成小说「谷歌小发猫写作」
GHOST tool to access the database
七、jmeter发出请求的逻辑
MySQL database
随机推荐
laravel database: query builder
赶紧进来修内功!!!带你认识C语言中各种进制数和原码反码补码.
[uniapp applet] view container cover-view
浅学软件逆向笔记(2)
非常菜的一个批量布置waf脚本
Using PyGame's Bubble Sort Visualizer
iNFTnews | Metaverse brings new ideas for enterprise development
FreeRTOS知识小结
淘宝API常用接口列表与申请方式
mmdetection最新版食用教程(一):安装并运行demo及开始训练coco
mysql 索引和 pgsql 索引 命名区别
redis介绍&命令&性能相关&缓存穿透
10分钟快速入门RDS【华为云至简致远】
最高法院关于婚姻案件诉讼程序的一些解答
常见的网络安全术语之一
2022年11大最佳缺陷管理工具盘点
MVCC,主要是为了做什么?
论文解读(soft-mask GNN)《Soft-mask: Adaptive Substructure Extractions for Graph Neural Networks》
【uniapp小程序】视图容器cover-view
【论文阅读】RAL 2022: Receding Moving Object Segmentation in 3D LiDAR Data Using Sparse 4D Convolutions