UVA 11888 - Abnormal 89's(Manachar)

UVA 11888 - Abnormal 89‘s

题目链接

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

思路:利用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's(Manachar),布布扣,bubuko.com

UVA 11888 - Abnormal 89's(Manachar)

时间: 2024-08-09 06:43:26

UVA 11888 - Abnormal 89's(Manachar)的相关文章

UVA 11888 - Abnormal 89&amp;#39;s(Manachar)

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="">题目链接 题意:给定一个字符串.推断类型.一共三种.两个回文拼接成的,

UVa 11888 Abnormal 89&#39;s

方法:Manacher Manacher算法在O(length) 时间内求出各个回文子串的长度.O(length) 时间检查时那一种情况. code: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <string> 6 #include <vector> 7 #include <st

千穗谷大家空心砖接着看见数据库恢复

pinterest.com/youzhenqu/%E6%BF%89%E6%BA%AA%E5%8E%BF%E5%93%AA%E9%87%8C%E6%9C%89%E6%89%BE%E5%B0%8F%E5%A7%90%E6%9C%8D%E5%8A%A1%E7%94%B5%E8%AF%9D%E4%BF%A1%E6%81%AF pinterest.com/youzhenqu/%E7%95%8C%E9%A6%96%E6%89%BE%E5%B0%8F%E5%A7%90%E4%B8%8A%E9%97%A8%E5

7. 及时发布。除非真正的用户接触到你的产品并给予反馈

7. 及时发布.除非真正的用户接触到你的产品并给予反馈,你永远都不会知道你的产品是好是坏. 8. 尽快发布,经常发布.不要惦记着再增加一些其它功能.只要能达到可以用来收集用户反馈的最小功能集合,那就发布它.收集反馈信息,反复这个过程,发布下一 个版本.下一个版本,越快越好.如果你3个月才发布出第一版面向用户的产品,你拖延的太久了.如果3个星期才发布一次更新包,你拖延的太久了.如果不能一 周几次,那每周发布一次更新.每3周发布一次重大更新. 9. 唯一有意义的事是你的产品的好坏.其它的都是鸡毛蒜皮

否极泰来接电话高科技电话施

http://www.yhd.com/ctg/s2/c19606-0-60977/%E8%BF%9E%E4%BA%91%E6%B8%AF%E6%B5%B7%E5%B7%9E%E5%8C%BA%E5%93%AA%E9%87%8C%E6%9C%89%E6%89%BE%E5%AD%A6%E7%94%9F%E5%A6%B9%E6%89%93%E7%82%AE%E4%B8%8A%E9%97%A8%E6%9C%8D%E5%8A%A1%E5%8C%85%E5%A4%9C%E7%94%B5%E8%AF%9D%2

[2016-02-03][UVA][514][Rails]

时间:2016-02-03 22:24:52 星期三 题目编号:UVA 514 题目大意:给定若干的火车(编号1-n),按1-n的顺序进入车站, 给出火车出站的顺序,问是否有可能存在 分析:    FIFO,用栈模拟一遍即可, 方法:    根据输入的顺序,从1-n开始,当前操作的为i 如果i是当前对应的编号,那么直接跳过(进入B) 如果不是,根据当前需求的编号,小于i,就从栈顶弹出一个元素, 看这个元素是否是需求的,是则继续.否则NO 1 2 3 4 5 6 7 8 9 10 11 12 13

Uva 11464 偶数矩阵

题目链接:https://uva.onlinejudge.org/external/114/11464.pdf 和开关问题类似,只不过现在是用的位运算操作更简单了,其中要注意的是,只能将0变成1. 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define inf 0x3f3f3f3f 6 7 int a[20][20]; 8 int b[20][20]; 9 int n; 10 11 int dr[3] = {-1,0,0}

UVa 1451 Average -斜率优化

A DNA sequence consists of four letters, A, C, G, and T. The GC-ratio of a DNA sequence is the number of Cs and Gs of the sequence divided by the length of the sequence. GC-ratio is important in gene finding because DNA sequences with relatively high

[题解]UVa 12661 Funny Car Racing - spfa

很简单的一道最短路问题.分情况处理赛道的打开和关闭. Code 1 /** 2 * UVa 3 * Problem#12661 4 * Accepted 5 * Time:50ms 6 */ 7 #include<iostream> 8 #include<fstream> 9 #include<sstream> 10 #include<cstdio> 11 #include<cstdlib> 12 #include<cstring>