题目链接:http://codeforces.com/gym/100971/problem/K

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<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define LL long long
const int N=2e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=; char a[N];
int checkl(int l,int r,int n,int L)
{
while(r<=n)
{
while(a[l]!=a[r])
{
if(L!=)return ;
L=l;
l--;
}
l--;r++;
}
return L;
}
int checkr(int l,int r,int n,int R)
{
while(l>=)
{
while(a[l]!=a[r])
{
if(R!=n)return ;
else R=r;
r++;
}
l--;r++;
}
return R;
}
int main()
{
scanf("%s",a+);
int n=strlen(a+);
if(n%==)
{
int ans=checkl(n/,n/+,n,);
if(ans)return *printf("YES\n%d\n",ans);
ans=checkr(n/-,n/+,n,n);
if(ans)return *printf("YES\n%d\n",ans);
puts("NO");
}
else
{
int ans=checkl(n/+,n/+,n,);
if(ans)return *printf("YES\n%d\n",ans);
ans=checkr(n/,n/+,n,n);
if(ans)return *printf("YES\n%d\n",ans);
puts("NO\n");
}
return ;
}

codeforces gym 100971 K Palindromization 思路的更多相关文章

  1. codeforces Gym 100971 A、B、C、F、G、K、L

    A题  直接把问号全部变为陆地如果所有陆地连通    那么再逐个把刚才变成陆地的问号变为水如果依旧连通有多种解 为什么我的代码跑不过去,和网上的题解思路一模一样!!?? #include<cst ...

  2. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  3. Codeforces gym 100971 D. Laying Cables 单调栈

    D. Laying Cables time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面

    K - Cross SpiderTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  5. codeforces gym 101164 K Cutting 字符串hash

    题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #prag ...

  6. codeforces gym 100357 K (表达式 模拟)

    题目大意 将一个含有+,-,^,()的表达式按照运算顺序转换成树状的形式. 解题分析 用递归的方式来处理表达式,首先直接去掉两边的括号(如果不止一对全部去光),然后找出不在括号内且优先级最低的符号.如 ...

  7. Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )

    题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...

  8. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  9. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

随机推荐

  1. linux 安装python3 date更新

    http://linux.51yip.com/ ntpdate -u ntp.aliyun.com   更新时间 centos 默认是有 python的,是2.7.5的 重启网络的命令  -- sys ...

  2. Step3 SQL Server 通过备份文件初始化复制

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 搭建过程(Process) 注意事项(Attention) 疑问(Questions) 参考文 ...

  3. linux--- sort,uniq,cut,wc命令

    1.sort [-fbMnrtuk] [file or stdin] -f :忽略大小写的差异,例如 A 与 a 视为编码相同: -b :忽略最前面的空格符部分: -M :以月份的名字来排序,例如 J ...

  4. Golang字符串函数认识(一)

    package main import ( "fmt" "strings" "strconv" ) func main(){ //返回字符串 ...

  5. P2233 [HNOI2002]公交车路线

    洛咕原题 dp->矩阵乘法 首先我们可以得出一个状态转移方程 f[i][j]=f[i-1][j-1]+f[i-1][j+1] 蓝后发现,我们可以把这转化为一个8*8的转移矩阵 然后跑一遍矩阵快速 ...

  6. oci7编译报’olog’等未定义的引用问题

    前一天在测试一个数据导出的时候,发现oci7编译的时候报了一大堆类似"’oparse’未定义的引用问题",这通常是因为找不到实现库的原因,但是oci相关的库又都是存在的,用oci7 ...

  7. Html5之Web存储

    localStorage 方法存储的数据没有时间限制.第二天.第二周或下一年之后,数据依然可用. sessionStorage 方法针对一个session 进行数据存储.当用户关闭浏览器窗口后,数据会 ...

  8. python简说(一)if,for等

    一.python简说 python可以用于自动化测试.web开发.数据分析.AI python.自动化运维,第三方模块最多的一个语言. 编译型语言 c.c++ 要运行,先要编译,编译成二进制的. 解释 ...

  9. bzoj 3489 A simple rmq problem - 线段树

    Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直 ...

  10. bash 变量

    本地变量: 变量赋值:name=value 变量引用:${name}  , $name "":变量名会替换为其值 '':变量名不会替换为其值 查看变量: set 撤销变量:unse ...