BNUOJ 52516 Just A String
$KMP$。
枚举每一个后缀,去原串中进行匹配,每次匹配到原串到$i$位置的后缀与这次枚举的后缀的前缀,更新答案。
#include<bits/stdc++.h>
using namespace std; int T;
char a[];
int len1,len2;
int nx[];
long long ans; void getNext(int x)
{
int j, k;
j = x;
k = x-;
nx[x] = x-;
while(j < len1)
if(k == x- || a[j] == a[k])
nx[++j] = ++k;
else
k = nx[k]; } void KMP_Index(int x)
{
int i = , j = x;
getNext(x); while(i < len1 )
{
if(j == x- || a[i] == a[j])
{
if(j!=x-)
{
long long B = (long long)(j-x+);
long long A = (long long)(i+-B);
long long C = (long long)(len2-B);
ans=ans^(A*B*B*C);
}
i++;
j++; }
else j = nx[j];
}
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%s",a);
len1 = strlen(a); ans=;
for(int i=; i<len1; i++)
{
len2 = len1-i;
memset(nx,,sizeof nx);
KMP_Index(i);
}
printf("%lld\n",ans);
}
return ;
}
BNUOJ 52516 Just A String的更多相关文章
- bnuoj 34985 Elegant String DP+矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...
- BNUOJ 34985 Elegant String 2014北京邀请赛E题 矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 题目大意:问n长度的串用0~k的数字去填,有多少个串保证任意子串中不包含0~k的 ...
- BNUOJ 34990 Justice String
Justice String Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java cla ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- bnuoj 25659 A Famous City (单调栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...
- bnuoj 25662 A Famous Grid (构图+BFS)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 #include <iostream> #include <stdio.h ...
- bnuoj 4209 Triangle(计算几何)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4209 题意:如题 题解:公式直接计算,或者角平分线求交点 [code1]: #include < ...
- bnuoj 33656 J. C.S.I.: P15(图形搜索题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=33656 [题解]:暴力搜索题 [code]: #include <iostream> # ...
随机推荐
- js获取本周、上周的开始结束时间
这两天在做一个报表体统,其中涉及到了一个根据本周,上周,本月,上月的时间来进行查询的问题,在这个我就教一下大家怎么实现,大家如果有更好的实现方法的,我也希望大家能说出来,我们交流交流. 首先呢,我写了 ...
- 本地文件夹如何断开svn连接
最近遇到一个问题,svn的项目down失败,一不小心点了删除准备重新上传,发现本地的文件已有svn源信息,提交更新均报再找不到此文件路径. 于是想着删除此文件夹的svn信息,经过一番百度,以下方法测试 ...
- 云风pbc源码alloc.c
#include <stdlib.h> #include <stdio.h> // 用于统计内存的申请和释放次数匹配 ; void * _pbcM_malloc(size_t ...
- 阿里iconfont引入方法
原文:iconfont的引入方法 第一步:使用font-face声明字体@font-face {font-family: 'iconfont';src: url('iconfont.eot'); ...
- NYOJ 1022 合纵连横 (并查集)
题目链接 描述 乱世天下,诸侯割据.每个诸侯王都有一片自己的领土.但是不是所有的诸侯王都是安分守己的,实力强大的诸侯国会设法吞并那些实力弱的,让自己的领土面积不断扩大.而实力弱的诸侯王为了不让自己的领 ...
- 71.Adam Taylor玩转MicroZed系列第82部分:简单通信接口第2部分
By Adam Taylor 从上周的博客开始,我们已经进入到Zedboard(而不是MicroZed)板上的OLED显示模块的编程了.然而在正式进入具体的OLED编程之前,我认为有必要验证我们是否已 ...
- python实战===python程序打包成exe
推荐PyInstaller项目www.pyinstaller.org 安装方法: 先跑pip install pywin32再跑pip install pyinstaller即可 可用一句命令打包 ...
- python模块之xlrd,xlwt,读写execl(xls,xlsx)
安装xlrd,xlwt pip install xlrd xlwt xlrd读取execl [环境ipython python2.7.5] import xlrd book = xlrd.open_w ...
- Webcollector应用(二)
先吐槽一句哀家的人品,总在写好代码之后,网站默默的升级,没有一点点防备... 一.加代理 爬取一个网站的时候,爬了不到一半,IP被封了,整个内部局域网的所有电脑都不能访问网站了. public cla ...
- 1、CentOS 6 安装GitLab
1.安装和配置必需的依赖项 在CentOS上将系统防火墙打开HTTP和SSH访问. sudo yum install -y curl policycoreutils-python openssh-se ...