【Gym 100971K】Palindromization
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.
The input contains a string s of length (2 ≤ |s| ≤ 200000), consisting of lowercase Latin letters.
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).
evertree
YES
2
emerald
NO
aa
YES
2
从左右两边往中间移动,如果相同,l++,r--,如果不同,第一次循环i==0时,则让l++,第二次循环则让r--,最后判断不同的出现了几次。如果dif是0,l>=r代表本身就是回文,则去掉l位置的字符。
#include <cstring>
#include <cstdio>
#define N 100005
char s[N<<];
int len,l,r,dif,at;
int main() {
scanf("%s",s);
len=strlen(s);
for(int i=;i<;i++){
dif=;
l=,r=len-;
while(l<r){
if(s[l]!=s[r]){
dif++;
if(i){
at=r;
r--;
}else {
at=l;
l++;
}
}
if(s[l]==s[r]){
l++;
r--;
}
}
if(l>=r&&dif==)at=l;
if(dif<){
printf("YES\n%d\n",at+);
break;
}
}
if(dif>)puts("NO");
}
【Gym 100971K】Palindromization的更多相关文章
- 【 Gym 101116K 】Mixing Bowls(dfs)
BUPT2017 wintertraining(15) #4H Gym - 101116K 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接 ...
- 【 Gym - 101124E 】Dance Party (数学)
BUPT2017 wintertraining(15) #4G Gym - 101124 E.Dance Party 题意 有c种颜色,每个颜色最多分配给两个人,有M个男士,F个女士,求至少一对男士同 ...
- 【Gym - 101124A】The Baguette Master (数学,几何)
BUPT2017 wintertraining(15) #4F Gym - 101124A 题意 给定画框宽度,画的四边和一个对角线长度,求画框外沿周长. 题解 过顶点做画框的垂线,每个角都得到两个全 ...
- 【 Gym - 101138K 】 The World of Trains (DP)
BUPT2017 wintertraining(15) #4E Gym - 101138K 题意 N节车厢的火车,每节车厢容量是1~K,那么有\(K^N\)种火车. 求选择D个连续的且容量相同的车厢的 ...
- 【 Gym - 101138J 】Valentina and the Gift Tree(树链剖分)
BUPT2017 wintertraining(15) 4 D Gym - 101138J 数据 题意 n个节点的一棵树,每个节点的权值为g,q个询问,树上的节点U-V,求U到V的路径的最大子段和. ...
- 【 Gym - 101138F 】GukiZ Height (数学)
BUPT2017 wintertraining(15) #4 C Gym - 101138F 题意 初始高度0,目标值h,第i天目标值会下降i,当前高度会改变a[i%n],求高度不小于目标值的最早的时 ...
- 【 Gym - 101138D 】Strange Queries (莫队算法)
BUPT2017 wintertraining(15) #4B Gym - 101138D 题意 a数组大小为n.(1 ≤ n ≤ 50 000) (1 ≤ q ≤ 50 000)(1 ≤ ai ≤ ...
- 【Gym - 101164I】Cubes(dfs,剪枝)
BUPT2017 wintertraining(15) #4 A - I.Cubes Gym - 101164I 题意 将n拆成最少个立方数相加的形式. 题解 根据n的范围,立方数最大不超过400的立 ...
- 【GYM 102059】2018-2019 XIX Open Cup, Grand Prix of Korea
vp了一场gym,我又开心地划水了. A. Coloring Roads 题意:给定一棵树,树边一开始都是无色的,每次操作可以把一个点到根的路径染成某个颜色,每次询问当前树上出现过某个次数的颜色种数. ...
随机推荐
- poj3281 Dining
Dining Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14316 Accepted: 6491 Descripti ...
- 程序员级别鉴定书(.NET面试问答集锦)
作为一个.NET程序员,应该知道的不仅仅是拖拽一个控件到设计时窗口中.就像一个赛车手,一定要了解他的爱车 – 能做什么不能做什么. 本文参考Scott Hanselman给出的.NET问题列表,整理如 ...
- 定时取数据库的schema,并推送到git服务器
写了个脚本,定时去数据库取schema,并推送到公司的git里. #daily_schema.py #/usr/bin/env python import os import datetime,tim ...
- MongoDB JAVA API Filters
Filters 该过滤器类为所有的MongoDB的查询操作静态工厂方法.每个方法返回BSON类型,又可以传递给期望一个查询过滤器的任何方法的一个实例. eq:匹配等于指定值的值.gt:匹配大于指定值的 ...
- Android开篇(转)
转自:http://gityuan.com/android/ 一.简述 Android系统非常庞大.错中复杂,其底层是采用Linux作为基底,上层采用包含虚拟机的Java层以及Native层,通过系统 ...
- matlab取整 四舍五入
Matlab取整函数有: fix, floor, ceil, round.取整函数在编程时有很大用处.一.取整函数1.向零取整(截尾取整)fix-向零取整(Round towards zero):&g ...
- 如何在 ie6 中使用 "localStorage"
好吧,我只是个标题党,ie6 下根本无法使用跟 h5 沾边的 localStorage.今天要向大家介绍的是 ie 特有的 userData 的存储方式,并且对它进行封装,使得不支持 localSto ...
- ASP.NET的编译原理
http://www.cnblogs.com/mdy2001212/archive/2008/01/31/1060345.html
- 比较Windows Azure 网站(Web Sites), 云服务(Cloud Services)and 虚机(Virtual Machines)
Windows Azure提供了几个部署web应用程序的方法,比如Windows Azure网站.云服务和虚拟机.你可能无法确定哪一个最适合您的需要,或者你可能清楚的概念,比如IaaS vs PaaS ...
- spring配置属性的两种方式
spring配置属性有两种方式,第一种方式通过context命名空间中的property-placeholder标签 <context:property-placeholder location ...