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 ...
随机推荐
- Matlab基础部分2-数组和矩阵分析
矩阵块操作: 矩阵尺寸改变: 矩阵的查找: 矩阵的排序: 矩阵求和: 矩阵的求积: 矩阵的差分: 全零矩阵: 单位矩阵: 随机矩阵: 伴随矩阵: 方针行列式计算: 特征值: 对角矩阵: 三角矩阵: 矩 ...
- Javaweb笔记—03(BS及分页的业务流程)
DAO部分:中间层声明该有的变量 pagerBook pageData sumRow sumPage求出总的记录数id唯一标识:select count(id) as rowsum from book ...
- if语法
语法一: if 条件: 条件成立时执行的子代码块 age_of_girl=31 if age_of_girl > 30: print('阿姨好') 语法二:if + else if 条件 ...
- Fiddler(三)Fiddler设置手机抓包
一.前提 我们要实现手机抓包,必须要手机连接的wifi和PC段连接的wifi所处同一个局域网内,如果你使用的是笔记本,那么这个就好办了,如果你使用的是台式机,那么你还需要准备一个无线网卡.我使用的是F ...
- fjwc2019 D2T3 排序(堆)
#183. 「2019冬令营提高组」排序 贴一段ppt 考虑模拟出这个算法进行k轮(即外层的i循环到k)时的序列,之后再暴力模拟零散的步. 考虑这个算法在01序列上的表现,k轮后实际上就是将最开始的不 ...
- 探索RequestBody报com.alibaba.fastjson.JSONObject cannot be cast to xxx
今天使用RequestBody接受前端传过来的参数,以前接受字符串数组非常成功,这次把形参改成了List<User>,原本以为顺利接受参数并映射成User的list结构,结果竟然在我取us ...
- html5-Input类型
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>html5-Input类型& ...
- python简说(九)函数
一.列表生成式 s =[1,2,3,4,5,6,7,8]for i in s: print(i+1)res = [ i+1 for i in s]res = [str(i) for i in s] 二 ...
- 【Python56--爬取妹子图】
爬取网站的思路 第一步:首先分析爬取网站的连接地址特性,发现翻页图片的时候连接:http://www.mmjpg.com/mm/1570 ,http://www.mmjpg.com/mm/1569, ...
- android 6 中init.rc的生成过程【转】
本文转载自:https://blog.csdn.net/quhj/article/details/51819638 android 系统开机是会有一个初始化过程 init ,整个初始化过程是根据配置脚 ...