HDU 4821 String(2013长春现场赛I题)
题目链接: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题)的更多相关文章
- hdu 4813(2013长春现场赛A题)
把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
- HDU 4818 Golden Radio Base (2013长春现场赛B题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 进制转换. 现场根据题目给的两个公式,不断更新!!! 胡搞就可以了. 现场3A,我艹,一次循环开 ...
- HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...
- HDU 4815 Little Tiger vs. Deep Monkey 2013 长春现场赛C题
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 [题意] n个题目,每题有各自的分数,A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率 ...
- HDU 4764 Stone (2013长春网络赛,水博弈)
Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 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 ...
- HDU 4759 Poker Shuffle(2013长春网络赛1001题)
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
随机推荐
- react componentWillReceiveProps 使用注意
componentWillReceiveProps(nextProps) 请务必使用 nextProps 不要使用 this.props 1个小时的教训...
- mysql 获取当月日期天数
本月总共天数:SELECT TIMESTAMPDIFF(day,CURDATE(),(DATE_add(CURDATE(),INTERVAL 1 month)))
- 促使团队紧密协作[高效能程序员的修炼-N1]
在Jeff看来,团队里最重要的事情,是人与人之间地协作和沟通!所有的问题,其实都是人的问题.“不管什么问题,那总是人的问题”-温伯格.即,让你和团队陷入困境的最快的方法,就是认为技术是决定性的因素,而 ...
- 001_shell经典案例
一. 二. -n, --numeric-sort compare according to string numerical value -k, --key=KEYDEF sort via a key ...
- Python api认证
本节内容: 基本的api 升级的api 终极版api 环境:Djanao, 项目名:api_auto, app:api 角色:api端,客户端,黑客端 1.基本的api [api端] #api_aut ...
- 去除Android APP里面的广告
如何去除Android游戏软件中的广告:很多时候,我们下载好一款Andriod游戏软件,却被游戏软件中的广告弄的很烦.不停跳动的广告让人觉得非常不爽,而且在玩游戏的时候,还有可能点击到广告,中断游戏. ...
- SQL语句导致性能问题
前阵子,突然收到服务器的报警信息,于是上服务器找问题,我擦,top看到mysql占的%cpu高得把我吓尿了 从以上的信息看,相信大家已经可以定位到底是那个程序导致服务器CPU负载过高了,但我们要做的是 ...
- .NetCore生产环境下构建Consul(单个DC数据中心)的服务器健康检查
下载最新的consul程序 consul 启动方式有两种 server 和client 默认是client 如果你不需要记录数据可以用 consul agent -dev 来启动 consul age ...
- Spring Boot Mvc 单元测试
https://blog.csdn.net/hfmbook/article/details/70209162
- Solr7.4.0的API(Solrj)操作
一.SolrJ的概念 solr单机版服务搭建:https://www.cnblogs.com/frankdeng/p/9615253.html solr集群版服务搭建:https://www.cnbl ...