codeforces gym 100971 K Palindromization 思路
题目链接:http://codeforces.com/gym/100971/problem/K
2.0 s
256 MB
standard input
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.
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
题意:给你一个字符串,删除一个字符,是否形成回文,如果有,输出删除的位置;
思路:对于删除一个字符以后,这个字符串的对称轴的位置只有两个,所有枚举对称轴,复杂度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 思路的更多相关文章
- codeforces Gym 100971 A、B、C、F、G、K、L
A题 直接把问号全部变为陆地如果所有陆地连通 那么再逐个把刚才变成陆地的问号变为水如果依旧连通有多种解 为什么我的代码跑不过去,和网上的题解思路一模一样!!?? #include<cst ...
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- Codeforces gym 100971 D. Laying Cables 单调栈
D. Laying Cables time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 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 ...
- codeforces gym 101164 K Cutting 字符串hash
题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #prag ...
- codeforces gym 100357 K (表达式 模拟)
题目大意 将一个含有+,-,^,()的表达式按照运算顺序转换成树状的形式. 解题分析 用递归的方式来处理表达式,首先直接去掉两边的括号(如果不止一对全部去光),然后找出不在括号内且优先级最低的符号.如 ...
- Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )
题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
随机推荐
- Java学习技术分享:Java中的原子操作
学习java需要有一套完整的学习线路,需要有条理性,当下学习java已经有一段时间了,由当初的懵逼状态逐渐好转,也逐渐养成了写技术学习笔记的习惯,今天总结了一下java中的原子操作. 1.Java中的 ...
- 金九银十跳槽季,程序员面试点解析之Java专场
前言 近年来Java工程师这个岗位炙手可热,市场需求大,学习Java的人也越来越多,所以IT企业与求职者的选择都比较多,那么IT企业在面试时都会提哪些问题呢.下面为大家分享 Java高级工程师面试阿里 ...
- SpringMVC MultiActionController 默认方法名解析器
MultiActionController默认方法名解析器是指在请求的地址中加入指定方法名称 MultiActionController类具有一个属性methodNameResolver,方法名解析器 ...
- mycat->oracle报java.sql.SQLException: 无法从套接字读取更多的数据
今天下午,测试环境清算的时候又出现了之前的一个异常,这次把错误信息全部打出来了,java.sql.SQLException: 无法从套接字读取更多的数据,是使用mycat连接oracle的,如下所示: ...
- Lyft高管的技术团队管理实战
Lyft 的技术总监沈思维分享了他对于管理技术团队和打造工程文化的经验,也欢迎添加他的微信公众号"人家的屋顶"了解更多(微信公众号ID: othersroof).沈思维毕业于密歇根 ...
- linux 中部署 rsync 实现文件远程备份及 同步
客户端:数据源:服务端:数据接收方 rsync官方文档:https://www.samba.org/ftp/rsync/rsync.html 手动测试用“通过远程外壳访问"里的语法: 参考1 ...
- 牛客网数据库SQL实战(6-10)
6.查找所有员工入职时候的薪水情况,给出emp_no以及salary, 并按照emp_no进行逆序CREATE TABLE `employees` (`emp_no` int(11) NOT NULL ...
- topcoder srm 515 div1
problem1 link 暴力枚举即可. problem2 link 一共有24小时,所以最多有24个顾客.设$f[x][y][z]$表示还剩下$x$把刀,现在时间是$y$,以及来过的顾客集合为$z ...
- Python3 tkinter基础 Frame bind 鼠标移动事件 实时显示鼠标的位置
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- secureCRT的自动化脚本如何编写?
以等待字符串eth0的出现,出现后或者20秒后脚本执行reboot命令的脚本为例,示例如下: #$language = "VBScript" #$interface = " ...