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 ...
随机推荐
- logger日志模块
简单配合模式: import logging#简单配置logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s ...
- 在Vmware中安装CentOS7
想要安装linux系统,在电脑上先装一个虚拟机,当然装双系统也是可以的.首先准备材料,3步:1.从CentOS的官网上下载CentOS7,DVD ISO版本,大概4G左右.名称:CentOS-7-x8 ...
- css链接link
链接可以使用任何css属性,包括字体.颜色.背景等等. 链接有四个状态,可在四个状态时设置不同的属性 a:link - 正常,未访问过的链接 a:visited - 用户已访问过的链接 a:hover ...
- End of script output before headers错误解决方法
注意是否丢失两个换行符\n\n printf("Content-type: text/html;charset=utf-8\n\n");
- mvc 遇到的问题
VS2010无法加载项目,此安装不支持该项目类型. 错误产生的原因是以前是用2010建的,后来用2012打开,可能是经过转换后,2010又打不开了. 用VS2010无法加载项目,提示:无法打开项目文件 ...
- 移动端(微信等)使用 vConsole 调试 console
参考链接:https://blog.csdn.net/m0_37036014/article/details/80113635
- JVM内存结构之堆、栈、方法区以及直接内存、堆和栈区别
JVM内存结构之堆.栈.方法区以及直接内存.堆和栈区别 一. 理解JVM中堆与栈以及方法区 堆(heap):FIFO(队列优先,先进先出):二级缓存:*JVM中只有一个堆区被所有线程所共享:对象和数 ...
- 【python35.2--图形用户界面EasyGui】
一.猜字游戏 #猜字游戏(从1到10) import easygui as g import random g.msgbox('欢迎进入探险之路!') screct = random.randint( ...
- Selenium Java Selection的使用
用于向具有drop-down的选择框中输入内容 new Select(new ChromeDriver().findElement(By.cssSelector(" ..."))) ...
- Linux电源管理(五)thermal【转】
本文转载自:https://blog.csdn.net/zhouhuacai/article/details/78172267 版权声明:本文为博主原创文章,未经博主允许不得转载. https: ...