hdu 3336 Count the string(思维可水过,KMP)
以下不是KMP算法——
以下是kiki告诉我的方法,好厉害的思维——
就是巧用标记,先标记第一个出现的所有位置,然后一遍遍从标记的位置往下找。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; int main()
{
int xin,t,i,j,n,ans,id,xiabiao[],shunxu;
char ch[];
scanf("%d",&t);
while(t--)
{ memset(xiabiao,,sizeof(xiabiao));
scanf("%d",&n);
scanf("%s",ch);
id=;shunxu=;
ans=;
for(j=;j<n;j++)
{
if(ch[j]==ch[shunxu])
xiabiao[id++]=j;
}
ans+=id;
ans=ans%;
do
{
shunxu++;
xin=;
for(i=;i<id;i++)
{
if(xiabiao[i]+<n)
{
if(ch[xiabiao[i]+]==ch[shunxu])
{
xiabiao[xin++]=xiabiao[i]+;
}
}
}
ans+=xin;
ans=ans%;
id=xin;
}while(shunxu<n-);
printf("%d\n",ans);
}
return ;
}
hdu 3336 Count the string(思维可水过,KMP)的更多相关文章
- 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) ...
- 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 ...
- HDU 3336 Count the string(next数组运用)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3336 Count the string 查找匹配字符串
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3336:Count the string(数据结构,串,KMP算法)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 ...
- HDU 3336 Count the string KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...
- 【HDU 3336 Count the string】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- HDU 3336——Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
随机推荐
- android 数据库中的事务_银行转账示例
主java package com.itheima.transtation; import com.itheima.transtation.db.BankOpenHelper; import andr ...
- [翻译.每月一译.每日一段]Exploring Fonts with DirectWrite and Modern C++
Windows with C++ Exploring Fonts with DirectWrite and Modern C++ Kenny Kerr DirectWrite is an incred ...
- Nginx在嵌入式系统中的应用
-----------------本文转载自 http://blog.csdn.net/xteda/article/details/39708009 ------------------------- ...
- 【风马一族_Java】 Java的文件类 java.io
BufferedReader 从字符输入流中读取文本,缓冲各个字符,从而实现字符.数组和行的高效读取. 可以指定缓冲区的大小,或者可使用默认的大小.大多数情况下,默认值就足够大了. 通常,Reader ...
- Css调整字体间距
在span div 某些元素中有时候会用到调整字体的间距,设置方法: letter-spacing:15px;
- Win7在CMD命令行中使用管理员权限运行命令
使用命令: runas /user:administrator 需要执行的命令 如下:
- ECMAScript整理笔记(持续更新....)
参考文献: ECMAScript Array:http://www.jimmycuadra.com/posts/ecmascript-5-array-methods ECMAScript5兼容展示大全 ...
- DOS环境下含包并引用第三方jar的java程序的编译及运行
DOS环境下含包并引用第三方jar的java程序的编译及运行 1.程序目录机构 bin:class文件生成目录 lib:第三方jar包目录 src:源程序文件目录 2.程序代码: 3.程序编译 jav ...
- 初测WIN10
WIN10已经发布,通过百度直通车把WIN7升级成了WIN10,改变较大,不太习惯,用着不是很顺手. 吐槽几个问题 1.微软的Visual Studio 2015 Community版本,宣布是免费的 ...
- [译]Redis大冒险
原文:ALCA in Redis-land 一篇对使用Redis在NoSQL的世界中冒险之旅的总结. The legs of our journey 像每次出发一样,先对我们这次的旅程路线做个介绍: ...