题目

以下不是KMP算法——

以下是kiki告诉我的方法,好厉害的思维——

就是巧用标记,先标记第一个出现的所有位置,然后一遍遍从标记的位置往下找。

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int xin,t,i,j,n,ans,id,xiabiao[],shunxu;
  9. char ch[];
  10. scanf("%d",&t);
  11. while(t--)
  12. {
  13.  
  14. memset(xiabiao,,sizeof(xiabiao));
  15. scanf("%d",&n);
  16. scanf("%s",ch);
  17. id=;shunxu=;
  18. ans=;
  19. for(j=;j<n;j++)
  20. {
  21. if(ch[j]==ch[shunxu])
  22. xiabiao[id++]=j;
  23. }
  24. ans+=id;
  25. ans=ans%;
  26. do
  27. {
  28. shunxu++;
  29. xin=;
  30. for(i=;i<id;i++)
  31. {
  32. if(xiabiao[i]+<n)
  33. {
  34. if(ch[xiabiao[i]+]==ch[shunxu])
  35. {
  36. xiabiao[xin++]=xiabiao[i]+;
  37. }
  38. }
  39. }
  40. ans+=xin;
  41. ans=ans%;
  42. id=xin;
  43. }while(shunxu<n-);
  44. printf("%d\n",ans);
  45. }
  46. return ;
  47. }

hdu 3336 Count the string(思维可水过,KMP)的更多相关文章

  1. HDU 3336 Count the string(KMP的Next数组应用+DP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. hdu 3336 Count the string KMP+DP优化

    Count the string Problem Description It is well known that AekdyCoin is good at string problems as w ...

  3. HDU 3336 Count the string(next数组运用)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 3336 Count the string 查找匹配字符串

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. hdu 3336:Count the string(数据结构,串,KMP算法)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu 3336 Count the string -KMP&dp

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  7. HDU 3336 Count the string KMP

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...

  8. 【HDU 3336 Count the string】

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  9. HDU 3336——Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

随机推荐

  1. 济南学习 Day 2 T3 am

    [问题描述]m× m的方阵上有n棵葱,你要修一些栅栏把它们围起来.一个栅栏是一段沿着网格建造的封闭图形(即要围成一圈) .各个栅栏之间应该不相交.不重叠且互相不包含.如果你最多修k个栅栏,那么所有栅栏 ...

  2. mysql mmm高可用架构设计

    项目概述:搭建主从,双主,安装Perl模块  安装配置mmm软件  测试 硬件环境:4台虚拟PC 软件环境:rehl6.5 MySQL-5.6.26 percona-xtrabackup-2.3.4 ...

  3. SDRAM控制器

    1 初始化以及load mode 寄存器1 初始化以及load mode 寄存器 2  时间表 这里会有几个重要的时间周期: 3 AUTO REFRESH (自动刷新) 4 CAS(CL delay) ...

  4. ADO.NET基本操作(CRUD、Procedure、Transaction)

    模型沿用上篇博客所提到的学生.教师.课程,以详细的代码进行演示. 增删改查 添加学生.教师.课程 using System.Data.SqlClient; namespace Test { class ...

  5. 【Qt】Qt Assistant介绍【转】

    简介 Qt Assistant也就是我们常说的Qt助手,是一款用于呈现在线文档的工具. 简介 一分钟学会使用 Qt参考文档 Qt Assistant详解 命令行选项 工具窗口 文档窗口 工具栏 菜单 ...

  6. wordpress修改固定链接及修改链接后链接提示404错误的解决办法

    wordpress默认的url实在是不好看又不好记忆,而且还不利于SEO.因此,我就捣鼓着把url做一个自定义.自定义的方式如下: 建议使用/%postname%的形式,这样利于SEO. 修改之后,l ...

  7. 51nod 1021 石头归并

    1021 石子归并 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 N堆石子摆成一条线.现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆石子合 ...

  8. mikrotik/IPSec Dynamic End points Updater.rsc

    # IPSec Peer/Policy Updater for Dynamic WAN addresses # ============================================ ...

  9. mysql中log

    mysql的主从模式配置 1.改主库配置文件:D:\Program Files\MySQL\MySQL Server 5.5(my.ini/my.cnf)在下面加入 [mysqld] log=c:/a ...

  10. C# 顺序表操作

    虽然.NET已经是现实了Reverse(),但是学习算法有必要知道其是怎么实现的: private static void ReverseArray(int[] array) { int temp; ...