题目链接: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
  1. evertree
output
  1. YES
    2
input
  1. emerald
output
  1. NO
input
  1. aa
output
  1. YES
    2

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

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

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<vector>
  7. using namespace std;
  8. #define LL long long
  9. const int N=2e5+,M=1e6+,inf=1e9+;
  10. const LL INF=1e18+,mod=;
  11.  
  12. char a[N];
  13. int checkl(int l,int r,int n,int L)
  14. {
  15. while(r<=n)
  16. {
  17. while(a[l]!=a[r])
  18. {
  19. if(L!=)return ;
  20. L=l;
  21. l--;
  22. }
  23. l--;r++;
  24. }
  25. return L;
  26. }
  27. int checkr(int l,int r,int n,int R)
  28. {
  29. while(l>=)
  30. {
  31. while(a[l]!=a[r])
  32. {
  33. if(R!=n)return ;
  34. else R=r;
  35. r++;
  36. }
  37. l--;r++;
  38. }
  39. return R;
  40. }
  41. int main()
  42. {
  43. scanf("%s",a+);
  44. int n=strlen(a+);
  45. if(n%==)
  46. {
  47. int ans=checkl(n/,n/+,n,);
  48. if(ans)return *printf("YES\n%d\n",ans);
  49. ans=checkr(n/-,n/+,n,n);
  50. if(ans)return *printf("YES\n%d\n",ans);
  51. puts("NO");
  52. }
  53. else
  54. {
  55. int ans=checkl(n/+,n/+,n,);
  56. if(ans)return *printf("YES\n%d\n",ans);
  57. ans=checkr(n/,n/+,n,n);
  58. if(ans)return *printf("YES\n%d\n",ans);
  59. puts("NO\n");
  60. }
  61. return ;
  62. }

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. JustOj 2043: N!

    题目描述 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出,赛后我们会检查代码,如有发现,该位同学总分记0分处理) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把 ...

  2. [转载]对称加密DES和TripleDES

    一. 对称加密 对称加密,是一种比较传统的加密方式,其加密运算.解密运算使用的是同样的密钥,信息的发送者和信息的接收者在进行信息的传输与处理时,必须共同持有该密码(称为对称密码).因此,通信双方都必须 ...

  3. NoSql Cassandra

    我们为什么要使用NOSQL非关系数据库? 随着互联网web2.0网站的兴起,非关系型的数据库现在成了一个极其热门的新领域,非关系数据库产品的发展非常迅速.而传统的关系数据库在应付web2.0网站,特别 ...

  4. mysql01

    CREATE TABLE `student`( `studentNo` INT (4) NOT NULL PRIMARY KEY COMMENT '学号', `loginPwd` VARCHAR(20 ...

  5. Linux 编程简单示例代码

    Linux进程管理 编辑a.c 文件 #include <stdio.h> #include <unistd.h> int main() { printf( "Mes ...

  6. Linux 命令梳理

    Linux 命令梳理 待梳理命令 nohup 用户管理 useradd 新建用户 sudo useradd {user name} -s /bin/bash -d /data/{user name} ...

  7. 【Python56--爬取妹子图】

    爬取网站的思路 第一步:首先分析爬取网站的连接地址特性,发现翻页图片的时候连接:http://www.mmjpg.com/mm/1570  ,http://www.mmjpg.com/mm/1569, ...

  8. Ant build.xml详解

    Ant的概念 可能有些读者并不连接什么是Ant以及入可使用它,但只要使用通过Linux系统得读者,应该知道make这个命令.当编译Linux内核及一些软件的源程序时,经常要用这个命令.Make命令其实 ...

  9. uniGUI出新版本了,0.97.0.1081

    uniGUI出新版本了,0.97.0.1081,试用版0.97.0.1075,支持Delphi2006~XE7.下载地址是: http://www.unigui.com/downloads 已在XE6 ...

  10. 终于知道linux firefox不能播放 web在线词典的单词发音了! --通过banshee安装gstreamer1-libav/-plugins-ugly/plugins-bad三个mp3插件.

    mpg123 是一个 命令行的播放器, 他没有gui界面. 直接用 mpg123 test.mp3 就可以直接播放, 而且, 最终要的是, mpg123 自带了mp3的解码器. mpeg: movin ...