UVA 11888 - Abnormal 89's

option=com_onlinejudge&Itemid=8&page=show_problem&category=524&problem=2988&mosmsg=Submission+received+with+ID+14075396" target="_blank" style="">题目链接

题意:给定一个字符串。推断类型。一共三种。两个回文拼接成的,一个回文,其他

思路:利用Manachar处理出每一个位置的最长回文,然后扫描一遍去推断就可以

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = 200005; int t, p[N * 2], n, len;
char str[N], s[N * 2]; void manachar() {
len = 2;
s[0] = '@'; s[1] = '#';
for (int i = 0; i < n; i++) {
s[len++] = str[i];
s[len++] = '#';
}
s[len] = '\0';
int mx = 0, id;
for (int i = 1; i < len; i++) {
if (mx > i) p[i] = min(p[2 * id - i], mx - i);
else p[i] = 1;
while (s[i + p[i]] == s[i - p[i]]) p[i]++;
if (i + p[i] > mx) {
id = i;
mx = i + p[i];
}
}
} int judge() {
int need = 0;
for (int i = 2; i < len - 1; i++) {
if ((p[i] - 1) / 2 == need) {
int l = i + p[i] - 1;
int r = len - 1;
int mid = (l + r) / 2;
int lneed = need * 2;
if (s[i] != '#') lneed++;
int rneed = n - lneed;
if (rneed && rneed == p[mid] - 1) return 0;
}
if (s[i] != '#') need++;
}
if (p[len / 2] - 1 == n) return 1;
return 2;
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%s", str);
n = strlen(str);
manachar();
if (judge() == 0) printf("alindrome\n");
else if (judge() == 1) printf("palindrome\n");
else printf("simple\n");
}
return 0;
}

UVA 11888 - Abnormal 89&#39;s(Manachar)的更多相关文章

  1. UVA 1397 - The Teacher&#39;s Side of Math(高斯消元)

    UVA 1397 - The Teacher's Side of Math 题目链接 题意:给定一个x=a1/m+b1/n.求原方程组 思路:因为m*n最多20,全部最高项仅仅有20.然后能够把每一个 ...

  2. UVA - 10239 The Book-shelver&#39;s Problem

    Description Problem D The Book-shelver's Problem Input: standard input Output: standard output Time ...

  3. uva 167 - The Sultan&#39;s Successors(典型的八皇后问题)

    这道题是典型的八皇后问题,刘汝佳书上有具体的解说. 代码的实现例如以下: #include <stdio.h> #include <string.h> #include < ...

  4. 【UVA】658 - It&#39;s not a Bug, it&#39;s a Feature!(隐式图 + 位运算)

    这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 < ...

  5. 供销大集-JS修改

    aes("a123456") 1.搜索password 可以猜测 寻找匹配项 然后把密码 给t 2.也可以直接直接从这里往上,找到一个 encrypt函数下断点调试输出 funct ...

  6. Java用来进行批量文件重命名,批量提取特定类型文件

    原因: 因为在网上下载视频教程,有的名字特别长,一般都是机构或者网站的宣传,不方便直接看到视频的简介,所以做了下面的第一个功能. 因为老师发的课件中,文件夹太多,想把docx都放在同一个文件夹下面,一 ...

  7. 记录一个多核CPU负载不均衡问题(动态绑定进程到指定cpu:taskset -pc $CPU $PID)

    昨晚和一位读者朋友讨论了一个问题:在一台多核 CPU 的 Web 服务器上,存在负载不均衡问题,其中 CPU0 的负载明显高于其它 CPUx,进一步调查表明 PHP-FPM 的嫌疑很大.话说以前我曾经 ...

  8. Power Map

    推荐64位版本Office,但会遇到以下问题 建议大多数用户使用 32 位 Office 我们建议使用 32 版本的 Office,因为它与大多数其他应用程序更加兼容,尤其是第三方加载项.这也是默认安 ...

  9. ibatis把表名作为一个参数报错问题的解决方案

    用ibatis的时候,想把表名也作为一个参数传进去,可是报错了,在ibatis配置文件里面是#resource#的方式,报错信息如下: org.apache.cxf.interceptor.Fault ...

随机推荐

  1. Fedora 14 安装完后的设置 添加源 更新软件

    1.添加源:   (1)上海交大源:应用程序->系统工具->终端 输入 su    输入密码 输入   nano /etc/yum.repos.d/sjtu.repo 辅之以下内容: [F ...

  2. docker基础——自定义镜像、创建私有仓库、查看 docker 运行状态

    一.自定义镜像 1,案例1 要求:请自定义一个 docker 镜像,基于 hub.c.163.com/library/centos,要求创建出来的镜像在生成容器的时候,可以直接使用 ifconfig ...

  3. poj 2079 Triangle

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9835   Accepted: 2951 Descript ...

  4. CF 451E Devu and Flowers

    可重集的排列数 + 容斥原理 对于 \(\{A_1 * C_1, A _2 * C_2, \cdots, A_n * C_n\}\)这样的集合来说, 设 \(N = \sum_{i = 1} ^ n ...

  5. jquery 同源跨域请求整理

    //同源ajax请求数据 function getData(url,paramjson,fn) { $.ajax({ type : "POST", //提交方式 url : url ...

  6. 【MFC】error RC2108: expected numerical dialog constant(转)

    原文转自 http://blog.csdn.net/renyhui/article/details/23120469 [解决方案]在控件ID后面添加 "Static", SS_BI ...

  7. Linux spi驱动分析(二)----SPI核心(bus、device_driver和device)

    一.spi总线注册 这里所说的SPI核心,就是指/drivers/spi/目录下spi.c文件中提供给其他文件的函数,首先看下spi核心的初始化函数spi_init(void).程序如下: 点击(此处 ...

  8. 在Eclipse中打开Hadoop工程

    1. 安装虚拟机,我用的是VMware Workstation 12 Player 2. 在VM中安装Ubuntu,我用的镜像文件是ubuntu-15.10-desktop-amd64.iso 3. ...

  9. 使用vue-element-admin框架开发时遇到的跨域问题

    之前 使用js和jquery开发时也碰到过接口请求时的跨域问题, 但是在使用vue-element-admin开发也碰到这个问题,而且不能使用之前的方法解决,查过不少资料,找到一个很好的方法解决了这个 ...

  10. Codeforces 919 A. Supermarket

    这场cf有点意思,hack场,C题等于1的特判hack很多人(我hack成功3个人,上分了,哈哈哈,咳咳...) D题好像是树形dp,E题好像是中国剩余定理,F题好像还是dp,具体的不清楚,最近dp的 ...