题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821

字符串题。

现场使用字符串HASH乱搞的。

枚举开头!

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <math.h>
using namespace std; int HASH;
const int MAXN = ;
int now ;
struct HASHMAP
{
int head[],next[MAXN],size;
unsigned long long state[MAXN];
int f[MAXN];
void init()
{
size = ;
for(int i = ;i < HASH ;i++)
head[i] = -;
//memset(head,-1,sizeof(head));
}
int insert(unsigned long long val,int _id)
{
int h = val % HASH;
for(int i = head[h];i != -;i = next[i])
{
if(val == state[i])
{
int tmp = f[i];
f[i] = _id;
return tmp;
}
}
f[size] = _id;
state[size] = val;
next[size] = head[h];
head[h] = size++;
return ;
}
}H; const int SEED = ;
unsigned long long P[MAXN];
unsigned long long S[MAXN];
unsigned long long a[MAXN];
char str[MAXN]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
P[] = ;
for(int i = ;i < MAXN;i++)
P[i] = P[i-]*SEED;
int M,L;
now = -;
while(scanf("%d%d",&M,&L) == )
{
now --;
scanf("%s",str);
int n = strlen(str);
S[] = ;
for(int i = ;i <= n;i++)
S[i] = S[i-]*SEED + str[i-];
int ans = ;
if(L>= )
HASH = ;
else
HASH = ;
for(int st = ;st <= L;st++)
{
H.init();
int tmp = ;
int cnt = ;
for(int i = st; i + L - <= n;i += L)
a[++cnt] = S[i+L - ] - S[i-] * P[L];
/*
for(int i = 1;i <= cnt;i++)
cout<<a[i]<<" ";
cout<<endl;
*/
for(int i = ;i <= cnt;i++)
{
int l = H.insert(a[i],i);
if(i - l >= M)continue;
ans += max(, i - M - tmp + );
tmp = max(tmp,l + );
//printf("%d %d\n",tmp,l);
}
ans += max(,cnt+ - M - tmp+);
}
printf("%d\n",ans);
}
return ;
}
/*
1
17239715954 17239715954 17417444844 17239715954
1 0
2 1
3 2
2
17417444844 17417444845 17595133743
1 0
1 0
3
17595133744 17595147076 17239702622
1 0
1 0
0
*/

HDU 4821 String(2013长春现场赛I题)的更多相关文章

  1. hdu 4813(2013长春现场赛A题)

    把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...

  2. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  3. HDU 4818 Golden Radio Base (2013长春现场赛B题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 进制转换. 现场根据题目给的两个公式,不断更新!!! 胡搞就可以了. 现场3A,我艹,一次循环开 ...

  4. HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...

  5. HDU 4815 Little Tiger vs. Deep Monkey 2013 长春现场赛C题

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 [题意] n个题目,每题有各自的分数,A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率 ...

  6. HDU 4764 Stone (2013长春网络赛,水博弈)

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

  7. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. HDU 4768 Flyer (2013长春网络赛1010题,二分)

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

随机推荐

  1. Sql语句 表中相同的记录(某个字段)只显示一条,按照时间排序显示最大或最小

    原始表数据:

  2. deeplearning.ai学习seq2seq模型

    一.seq2seq架构图 seq2seq模型左边绿色的部分我们称之为encoder,左边的循环输入最终生成一个固定向量作为右侧的输入,右边紫色的部分我们称之为decoder.单看右侧这个结构跟我们之前 ...

  3. spring的普通类中获取session和request对像

    在使用spring时,经常需要在普通类中获取session,request等对像. 1.第一钟方式,针对Spring和Struts2集成的项目: 在有使用struts2时,因为struts2有一个接口 ...

  4. linux串口驱动分析【转】

    转自:http://blog.csdn.net/hanmengaidudu/article/details/11946591 硬件资源及描述 s3c2440A 通用异步接收器和发送器(UART)提供了 ...

  5. Python_oldboy_自动化运维之路_socket编程(十)

    链接:http://www.cnblogs.com/linhaifeng/articles/6129246.html 1.osi七层 引子: 须知一个完整的计算机系统是由硬件.操作系统.应用软件三者组 ...

  6. findHomography和perspectiveTransform

    opencv中的两个函数,之前一直不明白这俩函数到底是要干嘛的. 得到两帧图像中的特征点后,就可以用findHomography得到单应性矩阵. 得到单应性矩阵后,可以 (1)根据相应的计算方法,由前 ...

  7. Laravel 自定义创建时间、更新时间字段

    Model 中,如果启动了 timestamps public $timestamps = true; 默认,laravel 会操作对应数据表的 created_at, updated_at 字段. ...

  8. java代码分页

    分页类 这个适用情况: 适用于前端页面已提供分页按钮样式的情况 分页规则: 首页,尾页,上页,下页 这四个按钮必定出现,中间分页动态生成5个 如:首 上 2 3 4 5 6 下 尾 public cl ...

  9. 采用MiniProfiler监控EF与.NET MVC项目(Entity Framework 延伸系列1)(转)

    前言 Entity Framework 延伸系列目录 今天来说说EF与MVC项目的性能检测和监控 首先,先介绍一下今天我们使用的工具吧. MiniProfiler~ 这个东西的介绍如下: MVC Mi ...

  10. 2016 版 Laravel 系列入门教程

    2016 版 Laravel 系列入门教程 (1) - (5) http://www.golaravel.com/post/2016-ban-laravel-xi-lie-ru-men-jiao-ch ...