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 ...
随机推荐
- 解析XML文档之一:使用SAX解析
使用sax解析xml方法总结 解析的的xml文档格式如下 <?xml version="1.0" encoding = "UTF-8"?> < ...
- Fragstats景观分析研究
QQ 交流群: Fragstats景观分析 加群链接:http://url.cn/N4wZ3N
- opencv 手写选择题阅卷 (二)字符识别
opencv 手写选择题阅卷 (二)字符识别 选择题基本上只需要识别ABCD和空五个内容,理论上应该识别率比较高的,识别代码参考了网上搜索的代码,因为参考的网址比较多,现在也弄不清是参考何处的代码了, ...
- 《Linux系统 date、cal、hwclock时间命令的用法》
date命令的用法: [root@apache ~]# date //查看当前系统的时间 Sat Jun 14 13:46:02 CST 2014 [root@apache ~]# date -s & ...
- HTML5应用开发:JavaScript库iScroll教程
目录 1. iScroll介绍 2. 安装和使用 3. 简单的iScroll例子 4. Pinch & Zoom 5. Snap to element 6. iScroll 详细参数 1. i ...
- UVA10361 -自动作诗机
UVA10361 - Automatic Poetry(自动作诗机) A Schuttelreim seems to be a typical German invention. The funny ...
- php编写简单的页面跳转功能
不多说,直接上. //确保magic_quotes_gpc在php.ini中移开启function CheckInput($value){ //去除反斜杠 if(get_magic_quotes_gp ...
- impdp ORA-29913: error in executing ODCIEXTTABLEOPEN callout
1.数据导出时的日志 ;;; Export: Release :: Copyright (c) , , Oracle and/or its affiliates. All rights reserve ...
- intellij idea 代码正常,但是编译出现 java:需要";"
1. 查看idea 的maven 插件是不是版本太低,发现应用里是用的jdk是1.7 maven插件是2.2.1 2. 查看应用编码,比如部分文件是GBK,里面有中文,而整个应用的编码是Utf-8
- 从零开始学ios开发(十八):Storyboards(下)
这篇我们完成Storyboards的最后一个例子,之前的例子中没有view之间的切换,这篇加上这个功能,使Storyboards的功能完整呈现.在Storyboards中负责view切换的东西叫做“s ...