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 ...
随机推荐
- SVM Kernel Functions
==================================================================== This article came from here. Th ...
- python爬虫:抓取下载电影文件,合并ts文件为完整视频
目标网站:https://www.88ys.cc/vod-play-id-58547-src-1-num-1.html 反贪风暴4 对电影进行分析 我们发现,电影是按片段一点点加载出来的,我们分别抓取 ...
- VBScript操作SFTP
示例代码主要通过VBScript实现对SFTP的上传下载功能 ' Return yyyyMM base on current date Function FormatCurrentDate() Cur ...
- oracle开机自启,开机自动关闭防火墙,开机监听自启
1.修改oratab 2,修改rc.local 3.关闭防火墙,设置开机时清空所有规则 参考文章: 1.https://blog.csdn.net/weeknd/article/details/726 ...
- 【干货】linux系统信息收集 ----检测是否被恶意程序执行了危险性命令
这些实战完全可以练习以下命令,已经找到需要观察的交互点,真实工作的时候,把数据都导入到自己U盘或者工作站内. 在kali 或者centos下训练都一样,关于kali教学,这里推荐掌控安全团队的课程:掌 ...
- Winform/WPF Clipboard之剪切复制粘贴
Winform // <summary> /// 复制或剪切文件至剪贴板(方法) /// </summary> /// <param name="files&q ...
- 大数据系列之数据仓库Hive命令使用及JDBC连接
Hive系列博文,持续更新~~~ 大数据系列之数据仓库Hive原理 大数据系列之数据仓库Hive安装 大数据系列之数据仓库Hive中分区Partition如何使用 大数据系列之数据仓库Hive命令使用 ...
- 【windows】在控制面板卸载软件的时候,出现2502,2503的问题
1. 打开“任务管理器”,找到“详细信息”的页签,将“explorer.exe”的进程结束任务 2.菜单栏的“文件”-->"建立新任务"--> 输入Explorer.e ...
- appium无ID、name定位处理【转】
1.关于没有name,没有ID的元素的定位---通用篇解题思路:因为没有name,id:其实剩下的选择已不多,要么xpath,要么className.xpath木有好印象(稳定性不高,加之1.0x后需 ...
- BI生态圈常用端口使用配置总结
Hadoop集群的各部分一般都会使用到多个端口,有些是daemon之间进行交互之用,有些是用于RPC访问以及HTTP访问.而随着Hadoop周边组件的增多,完全记不住哪个端口对应哪个应用,特收集记录如 ...