题目链接: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. object-c 数学计算公式

    1. 三角函数  double sin (double);正弦  double cos (double);余弦  double tan (double);正切  2 .反三角函数  double as ...

  2. CMD常用命令(一)

    常用命令大全 net>user heibai lovechina /add 加一个heibai的用户密码为lovechina net>localgroup Administrators h ...

  3. Shell脚本中实现切换用户并执行命令操作【转】

    第一种方法 cat test.sh #!/bin/bashsu - test <<EOFpwd;exit;EOF 执行结果图: 第二种方法 当然也可以用下面的命令来执行 复制代码代码如下: ...

  4. elasticsearch安装servicewrapper插件

    1)下载elasticsearch-servicewrappergit clone https://github.com/elasticsearch/elasticsearch-servicewrap ...

  5. 使用@SpringBootApplication注解

    很多Spring Boot开发者总是使用@Configuration , @EnableAutoConfiguration 和 @ComponentScan 注解他们的main类. 由于这些注解被如此 ...

  6. NEERC Southern Subregional 2011

    NEERC Southern Subregional 2011 A - Bonnie and Clyde solution 双指针搞搞就好. 时间复杂度:\(O(n)\) B - Building F ...

  7. [整理] mysql操作

    0.启动mysql(在windows中MySql以服务形式存在,在使用前应确保此服务已经启动) net start mysql 0.5获取版本信息 select version(); 1.root 登 ...

  8. Java封装概述

    1.封装概述 private  public 2.实现封装 例子: package com.java1995; public class Student { private String name; ...

  9. 排序算法的JS实现

    排序算法是基础算法,虽然关键在于算法的思想而不是语言,但还是决定借助算法可视化工具结合自己常用的语言实现一下 1.冒泡排序 基本思路:依次比较两两相邻的两个数,前面数比后面数小,不变.前面数比后面数大 ...

  10. CF1064B 【Equations of Mathematical Magic】

    题目要求解$a-(a\oplus x)-x=0$的解$x$的个数 移项得$a-x=a\oplus x$ $a$的二进制形式,应该是一个$01$串,异或的过程是不能影响到两个不同的位的,所以我们按位考虑 ...