字符串 - 近似回文词 --- csu 1328
近似回文词
Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328
analyse:
直接暴力枚举每一个终点,然后枚举回文串的半径即可.
Time complexity:O(n*m)
Source code:
// Memory Time
// 1347K 0MS
// by : Snarl_jsb
// 2014-10-03-14.25
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<climits>
#include<cmath>
#define N 1000010
#define LL long long
using namespace std; int k,real[],sta,max_len,cas=;
char st[],ss[];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
// freopen("C:\\Users\\ASUS\\Desktop\\cin.cpp","r",stdin);
// freopen("C:\\Users\\ASUS\\Desktop\\cout.cpp","w",stdout);
while(~scanf("%d",&k))
{
getchar();
gets(st);
int len=;
max_len=;
int l1=strlen(st);
for(int i=;i<l1;++i)
{
if((st[i]>='a'&&st[i]<='z')||(st[i]>='A'&&st[i]<='Z'))
{
if(st[i]>='A'&&st[i]<='Z')
st[i]+=;
ss[len]=st[i];
real[len]=i;
len++;
}
}
for(int i=;i<len;++i)
{
int error=,j;
for(j=;i+j<len&&i-j>=;++j)
{
if(ss[i+j]!=ss[i-j])
error++;
if(error>k)
break;
}
j--;
if(real[i+j]-real[i-j]+>max_len)
{
max_len=real[i+j]-real[i-j]+;
sta=real[i-j];
}
error=;
for(j=;i+j<len&&i-j+>=;++j)
{
if(ss[i+j]!=ss[i-j+])
error++;
if(error>k)
break;
}
j--;
if(j<=) continue;
if(real[i+j]-real[i-j+]+>max_len)
{
max_len=real[i+j]-real[i-j+]+;
sta=real[i-j+];
}
}
printf("Case %d: %d %d\n",cas++,max_len,sta+);
}
return ;
}
字符串 - 近似回文词 --- csu 1328的更多相关文章
- CSU 1328 近似回文词【最长回文字符串(三种方法)】
输入一行文本,输出最长近似回文词连续子串.所谓近似回文词是指满足以下条件的字符串: 1. S以字母开头,字母结尾 2. a(S)和b(S)最多有2k个位置不同,其中a(S)是S删除所有非字母字符并且把 ...
- CSU 1328: 近似回文词
省赛的A题...现场都没什么人做...其实就一暴力水题......坑死了... 1328: 近似回文词 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1 ...
- csuoj 1328: 近似回文词
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 1328: 近似回文词 Time Limit: 1 Sec Memory Limit: 1 ...
- csu-1328 近似回文词 和 最长回文字符串
原博文地址:http://blog.csdn.net/u012773338/article/details/39857997 最长回文子串 描述:输入一个字符串,求出其中最长的回文子串.子串的含义是: ...
- CSU 1328 近似回文词(2013湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 解题报告:中文题题意就不说了.还好数据不大,只有1000,枚举回文串的中心位置,然 ...
- Vijos1327回文词【动态规划】
回文词 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得到的 结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个回文词.你的任务是写 一个程序,求出将给定字符 ...
- 回文词_KEY
回文词 (palin.pas/c/cpp) [问题描述] 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得的结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个 ...
- 经典DP模型--回文词--IOI2000
[问题描述]回文词是一种对称的字符串--也就是说, 一个回文词, 从左到右读和从右到左读得到的结果是一样的. 任意给定一个字符串, 通过插入若干字符, 都可以变成一个回文词. 你的任务是写一个程序, ...
- 回文词——线性dp
#include<iostream> #include<cstdio> using namespace std; int n,f[5002][5002]; char str1[ ...
随机推荐
- 通过Typings为Visual Studio Code增强智能提示功能
缘起 最近在学习Node.js及ThinkJS这个框架,用vscode作为开发环境.默认情况下vscode对ThinkJS的代码提示并不好,所以研究了一下,原来可以同通过Typings来让vscode ...
- xcode 编译器在各个arch下面默认宏
$ clang -dM -E -arch armv7 -x c /dev/null #define OBJC_NEW_PROPERTIES 1 #define __APCS_32__ 1 #defin ...
- 【转帖】Moodle平台的5个新玩法
[玩坏Moodle平台]Moodle平台的5个新玩法 1.RSS订阅 Moodle平台可以导入外部博客(或其他提供RSS的服务),并显示在Moodle内置的博客系统中.无论是自己的个人网站还是他人的博 ...
- Turn off swi-prolog protocol output of ANSI terminal control sequences
To save a record of program execution in prolog, we use the special predicates: protocol and noproto ...
- Difference between SET, SETQ and SETF in LISP
SET can set the value of symbols; SETQ can set the value of variables; SETF is a macro that will ...
- HTML Hyperlink between and within pages
In HTML, we can use tag <a href=""> to create hyperlinks between and within pages. T ...
- 2015.10.14-TransactionScope测试
测试代码: ; ; List<string> lst = null; Action doSth = () => { using (var db = new TestSystemEnt ...
- kwm备忘
brew install homebrew/binary/kwm ==> Tapping homebrew/binary Cloning into '/usr/local/Library/Tap ...
- 聊聊IO多路复用之select、poll、epoll详解
本文转载自: http://mp.weixin.qq.com/s?__biz=MzAxODI5ODMwOA==&mid=2666538922&idx=1&sn=e6b436ef ...
- 谈"自驱力"
最新说明: 1.标题是为了博眼球取的,请不大家不要纠结具体薪资数字,我瞎取的 2.请注意素质,不要满口喷粪,不要搞人身攻击,尊重别人,就是尊重你自己 3.请大家就事论事,不要胡乱臆想,请站在全局的角度 ...