Calf Flac

It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes. Your job will be to detect these bovine beauties.

Ignore punctuation, whitespace, numbers, and case when testing for palindromes, but keep these extra characters around so that you can print them out as the answer; just consider the letters `A-Z' and `a-z'.

Find the largest palindrome in a string no more than 20,000 characters long. The largest palindrome is guaranteed to be at most 2,000 characters long before whitespace and punctuation are removed.

PROGRAM NAME: calfflac

INPUT FORMAT

A file with no more than 20,000 characters. The file has one or more lines which, when taken together, represent one long string. No line is longer than 80 characters (not counting the newline at the end).

SAMPLE INPUT (file calfflac.in)

Confucius say: Madam, I'm Adam.

OUTPUT FORMAT

The first line of the output should be the length of the longest palindrome found. The next line or lines should be the actual text of the palindrome (without any surrounding white space or punctuation but with all other characters) printed on a line (or more than one line if newlines are included in the palindromic text). If there are multiple palindromes of longest length, output the one that appears first.

SAMPLE OUTPUT (file calfflac.out)

11
Madam, I'm Adam

————————————————题解

话说样例什么鬼……?

Manacher最长回文子串匹配算法,简单易写

就是USACO上isalpha函数不好用????

/*
ID: ivorysi
LANG: C++
PROG: calfflac
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x5f5f5f5f
#define ivorysi
#define mo 97797977
#define hash 974711
#define base 47
#define fi first
#define se second
#define pii pair<int,int>
#define esp 1e-8
typedef long long ll;
using namespace std;
char str[],cmp[];
int l,cnt,pos[];
void init() {
char t[];
t[]='\0';
while(fgets(t+,,stdin)!=NULL) {
strcat(str+,t+);
//str[strlen(str+1)]='\0';
}
l=strlen(str+);
cmp[]='%';
cmp[++cnt]='@';
siji(i,,l) {
if(str[i]>='a' && str[i] <='z') {
cmp[++cnt]=str[i];
pos[cnt]=i;
cmp[++cnt]='@';
}
else if(str[i]>='A' && str[i] <='Z') {
cmp[++cnt]=str[i]-'A'+'a';
pos[cnt]=i;
cmp[++cnt]='@';
}
}
cmp[cnt+]='%';
cmp[cnt+]='\0';
}
int p[],id,mx;
void solve() {
init();
siji(i,,cnt) {
if(mx>i) {
p[i]=min(p[id*-i],mx-i+);
//要么就是对称的部分,如果它对称点长度超过了最大回文串的左边界,那就用右边界减去i
}
else {
p[i]=;
}
for(;cmp[i+p[i]]==cmp[i-p[i]];++p[i]) ;
if(mx<i+p[i]-) {
mx=i+p[i]-;
id=i;
}
}
id=;
siji(i,,cnt) {
if(p[id]<p[i]) id=i;
}
int ansl,ansr;
if(cmp[id+p[id]-]!='@') ansr=pos[id+p[id]-];
else ansr=pos[id+p[id]-];
str[ansr+]='\0';
if(cmp[id-p[id]+]!='@') ansl=pos[id-p[id]+];
else ansl=pos[id-p[id]+];
printf("%d\n%s\n",p[id]-,str+ansl);
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("calfflac.in","r",stdin);
freopen("calfflac.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}

USACO 6.2 Calf Flac的更多相关文章

  1. Calf Flac

    1.3.3 Calf Flac Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 223  Solved: 42[Submit][Status][Forum] ...

  2. USACO 1.3.3 Calf Flac(Manacher算法)

    Description 据说如果你给无限只母牛和无限台巨型便携式电脑(有非常大的键盘),那么母牛们会制造出世上最棒的回文.你的工作就是去寻找这些牛制造的奇观(最棒的回文). 在寻找回文时不用理睬那些标 ...

  3. USACO Section 1.3 : Calf Flac (calfflac)

    题意:据说假设你给无限仅仅母牛和无限台巨型便携式电脑(有很大的键盘),那么母牛们会制造出世上最优秀的回文. 你的工作就是去寻找这些牛制造的奇观(最优秀的回文). 在寻找回文时不用理睬那些标点符号.空格 ...

  4. USACO chapter1

    几天时间就把USACO chapter1重新做了一遍,发现了自己以前许多的不足.蒽,现在的程序明显比以前干净很多,而且效率也提高了许多.继续努力吧,好好的提高自己.这一章主要还是基本功的训练,没多少的 ...

  5. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. USACO . Your Ride Is Here

    Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...

  9. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

随机推荐

  1. gitlab的备份与恢复与迁移

    一.gitlab的备份1.1 创建备份目录,并授权 1 2 3 4 [root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-no ...

  2. 完美解决github访问速度慢

    1. 解决方法 2.解决方法 1. 修改本地hosts文件 windows系统的hosts文件的位置如下:C:\Windows\System32\drivers\etc\hosts mac/linux ...

  3. [HTML5和Flash视频播放器]Video.js 学习笔记(一 ) HLS库:videojs-contrib-hls

    DEMO地址:https://github.com/Tinywan/PHP_Experience https://github.com/videojs/videojs-contrib-hls 下载JS ...

  4. python3使用stmplib发送邮件

    代码如下: import smtplib from email.mime.text import MIMEText from email.header import Header from email ...

  5. nodejs express 上传文件 (格式 FormData)

    前台代码使用jQuery的ajax: <script type="text/javascript"> $(function(){ $('#file_upload').c ...

  6. web打印难题—背景不打印的简单不完美解决方案

    web打印在一些开发中是比较常见的需求,最简单的办法是使用css print进行控制:对于一些建议可以参考http://slodive.com/web-development/css-print-pa ...

  7. 洛谷P3960 [NOIP2017] 列队

    数据结构题还是挺好玩的 注意到每次只变动三个点:(x,y),(x,m),(n,m),其他地方都是整块移动. 可以开n+1个线段树,前n个存每行前m-1个人,最后一个存第m列的人. (x,y)位置的人出 ...

  8. Bzoj3352 [ioi2009]旅行商

    Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 36 Description 旅行商认定如何优化旅行路线是一个非常棘手的计算问题 ...

  9. 20155217 2016-2017-2 《Java程序设计》第8周学习总结

    20155217 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 15.1日志 15.1.1日志API简介 java.util.logging包提供了日志功能 ...

  10. mac nginx 安装及PHP配置

    安装nginx 1.安装brew命令 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/mas ...