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 ...
随机推荐
- 字节的高低位知识,Ascii,GB2312,UNICODE等编码的关系与来历
很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们看到8个开关状态是好的,于是他们把这称为"字节". 再后来,他们又做了一些可以处理 ...
- 简单工厂(Simple Pattern)模式
一.简单工厂(Simple Factory)模式 Simple Factory 模式根据提供给它的数据,返回几个可能类中的一个类的实例.通常它返回的类都有一个公共的父类和公共的方法. Simple F ...
- MySQL 密码增强插件
200 ? "200px" : this.width)!important;} --> 介绍 以前没有太注意MySQL密码安全策略的配置方法,只是人为了将密码设为复杂密码,但 ...
- 《搭建更新DNS集群服务》RHEL6
DNS服务器的更新: 一听就知道不止一台的DNS服务器,要是一台也用不着更新对吧?一般都是DNS集群. 一台DNS更新了,添加一条数据,下面的都要跟着它变. 主DNS服务器的配置 首先先配置DNS服务 ...
- 完美解决fixed 水平居中问题
群里的朋友问的,发现自己没写过:就写了下,原理和网上的fixed上下左右四个角的原理一样! 1.防止页面振动: body{ _background-image: url(about:blank); _ ...
- Markdown 使用说明
使用说明 ========= @[手册|帮助|Markdown] - **马克飞象**是一款专为印象笔记打造的Markdown编辑器. - 特别需要说明的一点是增加了`@(笔记本)[标签]`语法,以此 ...
- 重拾C,一天一点点
数据类型及长度 char 字符型,占用一个字节 int 整型,通常代表特定机器中整数的自然长度 short 16位 int 16位或32位 ...
- Windows下关于Composer使用时出现的问题及解决办法
问题一: Fatal error: Call to undefined method Composer\Package\CompletePackage::getTrans portOptions() ...
- NavigationBar的简单设置
http://blog.csdn.net/hufeng825/article/details/7643532#) .Label属性设置 titleLabel = [[UILabel alloc] in ...
- 全民wifi钓鱼来临----agnes安卓wifi钓鱼神器介绍
断断续续搞了一些无线的东西,从bt5的aircrack-ng的破无线(没怎么成功过)其实EWSA这个用GPU跑还算不错,可惜了我这显卡也只能每秒2500,到用c118在OsmocomBB基础上进行gs ...