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> # ...
随机推荐
- 驱动学习5: zynq实现点亮led
驱动代码: #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #i ...
- 2017北京国庆刷题Day1 morning
期望得分:100+100+100=300 实际得分:100+100+70=270 T1位运算1(bit) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK ...
- PowerShell入门
最近需要写个Windows的脚本,以前一直使用cmd.exe来写批处理脚本,这次接触到了PowerShell,准备把学习过程中学到的知识点整理在这里: 相关文章: 1.https://www.cnbl ...
- C# 实现java中 wiat/notify机制
最近在学习java,看到wiat/notify机制实现线程通信,由于平时工作用的C#,赶紧用C#方式实现一个demo. Java 代码: import java.util.ArrayList; imp ...
- MagicB.0—怎样设置电脑自动关机?
天太晚了,该睡觉了,可是你的东西也许正在下载,软件正在更新,总之电脑还有一些工作没有完成,又不需要你人为的守着,随他去吧!可是电脑已经工作了一天了,它也要休息一下,再者也不能浪费电力资源呀,那么就来使 ...
- 【BZOJ】3262: 陌上花开
[题意]三维偏序,给定n个点(x,y,z),求每个点和(0,0,0)组成空间中的点数,有重点.1<=x,y,z<=2*10^5,1<=n<=10^5. [算法]CDQ分治+树状 ...
- 在eclipse安装mybatis的插件
1.在help中打开 2.搜索mybatipse 3:功能简介 1:要查找某一个方法 在dao接口中某一个方法中 按住 Ctrl键 鼠标指到方法名称上 选择open xml 就会自动跳转 ...
- Java的继承和多态
看了博客园里面的一个文章,关于java的继承和多态: class A ...{ public String show(D obj)...{ return ("A and D"); ...
- Ubuntu 上更新 Flash 插件
2018-02-19 12:08:28 更新: 现在的 Google Chrome 浏览器自带了 Flash 支持,无需安装.而 Firefox 浏览器没有提供 Flash 支持,所以用 Firefo ...
- UVA题解二
UVA题解二 UVA 110 题目描述:输出一个Pascal程序,该程序能读入不多于\(8\)个数,并输出从小到大排好序后的数.注意:该程序只能用读入语句,输出语句,if语句. solution 模仿 ...