题意描述

  原题:

  

    一句话描述:对于一个0/1序列,求出其中异或意义下回文的子串数量。


题解

  我们可以看出,这个其实是一个对于异或意义下的回文子串数量的统计,什么是异或意义下呢?平常,我们对回文的定义是,对于任意$i$,$S[i]=S[n-i+1]$,而我们把相等改为异或操作,那么,当且仅当$1$与$0$相匹配时,返回值为$1$ 也就是 “真”。

  那么,我们可以尝试使用Manache算法来解决。当然,编程时,我们并不必真的去把0/1序列转换为数字序列,进行异或操作,这样会给自己增加一波常数(迷),我们构造一个to数组,$to[x]$数组的定义为 对于字符$x$ 我们允许匹配的对应字符,显然,$to['0']='1'$,$to['1']='0'$,特别的$ to['\#']='\#' $  $to['\$']='\$' $。(此处'#'与'$'是Manache算法的分隔字符与防止溢出字符,可以自定义)。

  对于Manache算法有任何不了解的地方,可以戳!!!这里!!!,又看不懂的地方,也可以联系文文(434935191)

  对于代码:

  

 #include<cstdio>
#include<algorithm>
#include<cstring>
const int maxn = ;
typedef unsigned long long ull;
char SS1[maxn],S[maxn],to[];
int n,len[maxn],tot=;
int main() {
scanf("%d%s",&n,SS1+);S[]='$',S[]='#';
for(register int i=;i<=n;++i) S[++tot]=SS1[i],S[++tot]='#';
to['']='',to['']='',to['#']='#',to['$']='$';
int pos=,mx=;ull ans=;
for(register int i=;i<=tot;i+=) {
len[i]=(i<mx?std::min(mx-i,len[(pos<<)-i]):);
while(S[i+len[i]]==to[S[i-len[i]]]) len[i]++;
if(len[i]+i>mx) {
mx=len[i]+i;pos=i;
}
ans+=len[i]>>;
}
printf("%llu\n",ans);
return ;
}

【BZOJ2084】【洛谷P3501】[POI2010]ANT-Antisymmetry(Manache算法)的更多相关文章

  1. [洛谷P3501] [POI2010]ANT-Antisymmetry

    洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...

  2. 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)

    洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...

  3. 洛谷 P3805 【模板】manacher算法

    洛谷 P3805 [模板]manacher算法 洛谷传送门 题目描述 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 字符串长度为n 输入格式 一行小写英文字符 ...

  4. 洛谷P4581 [BJOI2014]想法(玄学算法,拓扑排序)

    洛谷题目传送门 萝卜大毒瘤 题意可以简化成这样:给一个DAG,求每个点能够从多少个入度为\(0\)的点到达(记为\(k\)). 一个随机做法:给每个入度为\(0\)的点随机一个权值,在DAG上求出每个 ...

  5. 洛谷 P3496 [POI2010]GIL-Guilds

    P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...

  6. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  7. 洛谷 P3505 [POI2010]TEL-Teleportation

    P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...

  8. 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解

        这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...

  9. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

随机推荐

  1. 分享 - 普通程序员如何转向AI方向

    原作者:计算机的潜意识 原文链接,内容稍有改动,侵删 1. 目的2. AI领域简介3. 学习方法4. 学习路线 0) 领域了解1) 知识准备2) 机器学习3) 实践做项目4) 深度学习5) 继续机器学 ...

  2. inotify监测实例

    /************************************************************************* > File Name: inotify.c ...

  3. 105. Construct Binary Tree from Preorder and Inorder Traversal (Tree; DFS)

    Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...

  4. WebService超时

    1.web.config配置,<system.web></system.web>里面增加:<httpRuntime maxRequestLength="1024 ...

  5. golang之指针

    先上代码 package main import "fmt" type myInt int //匿名函数 //值的接收 //指针的接收 //*myint表示myInt的指针类型 / ...

  6. JavaScript RegExp.exec() 方法

    定义和用法: exec() 方法用于检索字符串中的正则表达式的匹配. 语法: RegExpObject.exec(string); RegExpObject:必须参数,正则表达式: string:必须 ...

  7. windows下使用redis

    一.下载windows版本的Redis 官网只提供linux版本的下载 官网下载地址:http://redis.io/download Redis 没有官方的Windows版本,但是微软开源技术团队( ...

  8. Resolving multicopy duplications de novo using polyploid phasing 用多倍体相位法解决多拷贝复制的新问题

    抽象.虽然单分子测序系统的兴起已经实现组装复杂地区的能力空前提高在基因组中,基因组中的长节段重复仍然是装配中具有挑战性的前沿. 分段重复同时具有丰富的基因并且倾向于大的结构重排,使得它们的序列的分辨率 ...

  9. PHP语言性能优化——少使用魔术方法

    对以下使用魔术方法和不适用魔术方法运行时间进行比较 使用魔术方法test1.php: <?php /** * 测试类 */ class test { private $name = " ...

  10. 自定义beans.xml文件实现Spring框架

    经过一天的补习,学习文件加载,java反射,JDom等知识,到了晚上终于能够搭出一个基于配置文件的简单spring框架实现! 首先我们先看看这个问题: 下面是两副图左边是项目结构图,右边是UML图: ...