博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces gym 100971 K Palindromization 思路
阅读量:4582 次
发布时间:2019-06-09

本文共 2125 字,大约阅读时间需要 7 分钟。

K. Palindromization
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

Mihahim has a string s. He wants to delete exactly one character from it so that the resulting string would be a palindrome. Determine if he can do it, and if he can, what character should be deleted.

Input

The input contains a string s of length (2 ≤ |s| ≤ 200000), consisting of lowercase Latin letters.

Output

If the solution exists, output «YES» (without quotes) in the first line. Then in the second line output a single integer x — the number of the character that should be removed from s so that the resulting string would be a palindrome. The characters in the string are numbered from 1. If there are several possible solutions, output any of them.

If the solution doesn't exist, output «NO» (without quotes).

Examples
input
evertree
output
YES 2
input
emerald
output
NO
input
aa
output
YES 2

 题意:给你一个字符串,删除一个字符,是否形成回文,如果有,输出删除的位置;

思路:对于删除一个字符以后,这个字符串的对称轴的位置只有两个,所有枚举对称轴,复杂度O(n);

#include
#include
#include
#include
#include
#include
using namespace std;#define LL long longconst int N=2e5+100,M=1e6+10,inf=1e9+10;const LL INF=1e18+10,mod=19260817;char a[N];int checkl(int l,int r,int n,int L){ while(r<=n) { while(a[l]!=a[r]) { if(L!=1)return 0; L=l; l--; } l--;r++; } return L;}int checkr(int l,int r,int n,int R){ while(l>=1) { while(a[l]!=a[r]) { if(R!=n)return 0; else R=r; r++; } l--;r++; } return R;}int main(){ scanf("%s",a+1); int n=strlen(a+1); if(n%2==0) { int ans=checkl(n/2,n/2+2,n,1); if(ans)return 0*printf("YES\n%d\n",ans); ans=checkr(n/2-1,n/2+1,n,n); if(ans)return 0*printf("YES\n%d\n",ans); puts("NO"); } else { int ans=checkl(n/2+1,n/2+2,n,1); if(ans)return 0*printf("YES\n%d\n",ans); ans=checkr(n/2,n/2+1,n,n); if(ans)return 0*printf("YES\n%d\n",ans); puts("NO\n"); } return 0;}

 

 

转载于:https://www.cnblogs.com/jhz033/p/7441705.html

你可能感兴趣的文章
testng入门教程11 TestNG运行JUnit测试
查看>>
FloatHelper
查看>>
异常处理
查看>>
分布式架构高可用架构篇_02_activemq高可用集群(zookeeper+leveldb)安装、配置、高可用测试...
查看>>
ORA-12560:TNS:协议适配器错误
查看>>
大数据量,海量数据 处理方法
查看>>
面向对象基础部分及模块
查看>>
less使用方法
查看>>
C#生成exe、dll版本号自动增加
查看>>
高效代码指泛型代替非泛型
查看>>
递归函数、匿名函数、内置函数
查看>>
第三周学习总结
查看>>
作业二:源程序版本管理软件和项目管理软件的优缺点
查看>>
jquery的DataTables插件的使用方法
查看>>
合并果子 2004年NOIP全国联赛普及组
查看>>
九度1457...
查看>>
重新开始学习javase_Exception
查看>>
排序命令sort
查看>>
Raspberry Pi开发之旅-同步时间
查看>>
Spinner的使用
查看>>