$KMP$。

枚举每一个后缀,去原串中进行匹配,每次匹配到原串到$i$位置的后缀与这次枚举的后缀的前缀,更新答案。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int T;
  5. char a[];
  6. int len1,len2;
  7. int nx[];
  8. long long ans;
  9.  
  10. void getNext(int x)
  11. {
  12. int j, k;
  13. j = x;
  14. k = x-;
  15. nx[x] = x-;
  16. while(j < len1)
  17. if(k == x- || a[j] == a[k])
  18. nx[++j] = ++k;
  19. else
  20. k = nx[k];
  21.  
  22. }
  23.  
  24. void KMP_Index(int x)
  25. {
  26. int i = , j = x;
  27. getNext(x);
  28.  
  29. while(i < len1 )
  30. {
  31. if(j == x- || a[i] == a[j])
  32. {
  33. if(j!=x-)
  34. {
  35. long long B = (long long)(j-x+);
  36. long long A = (long long)(i+-B);
  37. long long C = (long long)(len2-B);
  38. ans=ans^(A*B*B*C);
  39. }
  40. i++;
  41. j++;
  42.  
  43. }
  44. else j = nx[j];
  45. }
  46. }
  47.  
  48. int main()
  49. {
  50. scanf("%d",&T);
  51. while(T--)
  52. {
  53. scanf("%s",a);
  54. len1 = strlen(a);
  55.  
  56. ans=;
  57. for(int i=; i<len1; i++)
  58. {
  59. len2 = len1-i;
  60. memset(nx,,sizeof nx);
  61. KMP_Index(i);
  62. }
  63. printf("%lld\n",ans);
  64. }
  65. return ;
  66. }

BNUOJ 52516 Just A String的更多相关文章

  1. 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 ...

  2. BNUOJ 34985 Elegant String 2014北京邀请赛E题 矩阵快速幂

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 题目大意:问n长度的串用0~k的数字去填,有多少个串保证任意子串中不包含0~k的 ...

  3. BNUOJ 34990 Justice String

    Justice String Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java cla ...

  4. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  5. bnuoj 24251 Counting Pair

    一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...

  6. bnuoj 25659 A Famous City (单调栈)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...

  7. bnuoj 25662 A Famous Grid (构图+BFS)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 #include <iostream> #include <stdio.h ...

  8. bnuoj 4209 Triangle(计算几何)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=4209 题意:如题 题解:公式直接计算,或者角平分线求交点 [code1]: #include < ...

  9. bnuoj 33656 J. C.S.I.: P15(图形搜索题)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=33656 [题解]:暴力搜索题 [code]: #include <iostream> # ...

随机推荐

  1. Ubuntu+NDK编译openssl

    为了Android上使用libcurl且支持HTTPS协议,需要依赖openssl,因此先来了解一下如何编译OpenSSL1.编译ARM下的共享库(默认的)我使用的是guardianproject的o ...

  2. spring mvc入门配置

    现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了.不过 ...

  3. 使用git拉取github上的项目

    一. 安装Git 去Git官网,下载安装包,一路点next,默认安装. 安装之后,在空白处右键,菜单显示有 Git GUI Here 和 Git Bash Here ,表示Git安装成功. 二. 配置 ...

  4. Debian最完美安装flash的教程//适用于所有linux版本

    话说不管是新手还是老手,都离不开flash.没有flash的支持,菜鸟们也少了一些把玩linux的动力. flash有很多安装的方法,不过性能相差很大.这里的缘由就不重要了. 下面我介绍在chromi ...

  5. elasticsearch ik中文分词器的安装配置使用

    安装步骤  https://github.com/medcl/elasticsearch-analysis-ik 以插件形式安装: [elsearch@localhost elasticsearch- ...

  6. 集合框架小结-Collection

    1.集合框架作为处理对象的容器存在,基本接口是Collection,相对于数组而言的话,集合框架只能存储对象,但是长度是可变的.集合框架的关系图如下: 主要的内容是list.set.map, List ...

  7. opencv 高级拼接函数Stitcher

    Stitcher https://docs.opencv.org/trunk/d8/d19/tutorial_stitcher.html http://blog.csdn.net/czl389/art ...

  8. html 中的列表

    html 中列表可以分为 1.  无序列表(ul--li 的形式) 2.  有序列表(ol li的形式) 3.  定义列表(dl 的形式) 下面来看几种列表的具体内容: 1.无序列表. 无序列表的格式 ...

  9. 使用qt写的简单的图片浏览器

    功能特别简单,支持png,jpg,bmp,gif文件,支持自适应窗口大小,支持放大缩小,旋转功能还有点问题,支持上下按键选择图片 因为初学qt,所以很多东西都不太会,而且c++学的不是太好,没有怎么使 ...

  10. webgote的例子(4)Sql注入(SelectGET)

    SQL Injection (Select/GET) 本章内容 (查询显示中要注意的错误) 这里面我们看一下 movie的数值,选择表单中的当我们选择的二个的时候 move的值也变成了第二个,选择表单 ...