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 ...
随机推荐
- 2016.10.30 济南学习 Day2 下午 T1
他 [问题描述] 一张长度为N的纸带,我们可以从左至右编号为0 − N(纸带最左端标号为 0).现在有M次操作,每次将纸带沿着某个位置进行折叠,问所有操作之后纸带 的长度是多少. [输入格式] 第一行 ...
- C++模板实例化(1)
On-Demand实例化 当C++编译器遇到模板特化的时候,他会利用所给的实参替换对应的模板参数,从而产生该模板的特化.该过程是自动进行的.有时候也会被称为隐式实例化,或者是自动实例化. on-dem ...
- insertorupdate
MERGE INTO 运用的心得 最近完成一个功能,就是往表里插入数据,以party_id 和prod_id为联合主键,存在的更新,不存在的插入, ORACLE 10g 后可以试用MERGE INT ...
- TCP之Socket的编程
Socket是网络编程的一个抽象的概念,通常我们用Socket来表示服务器与客户端间的网络连接, 即用Socket表示"打开了一个网络连接", 而打开一个网络连接需要知道目标电脑的 ...
- thymeleaf 局部变量、属性优先级、注释
九.局部变量(local variable) 之前在th:each中遇到过局部变量 <tr th:each="prod : ${prods}"> ... </tr ...
- (三)开始在OJ上添加签到功能
在了解完OJ文件下的各个文件夹的主要作用后,我们开始往里面添加东西(其实只要知道各文件夹是干什么的后,添加东西也变得非常简单了) 一 在数据库中添加对应功能的字段. 我们这个学期才刚开数据库这门课,所 ...
- 查看SQL Server 备份信息
RESTORE HEADERONLY FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008\MSSQL\Back ...
- COALESCE在SQL拼接中的大用途
SQL拼接可以使得代码比较灵活,不会那么死板,对于维护也比较方便. 下面是简单的SQL拼接,同时也包含了隐式游标的概念吧,可以遍历表中的每一个字段 -------------------------- ...
- mootools和jquery冲突的解决
mootools-jquery 今天在做EcStore前台的做效果时,由于Jquery的插件比较多,于是就使用了Jquery的插件,但是发现会引起Mootools的冲突. 于是猛找资料,终于找到了,现 ...
- Qt窗口部件及子部件
QWidget类是所有用户界面对象的基类,被称为基础窗口部件. #include <QApplication> #include<QLabel> #include<QWi ...