BZOJ 4084 [Sdoi2015]双旋转字符串
题解:hash
至今不会unsigned long long 的输出
把B扔进map
找A[mid+1][lenA]在A[1][mid]中的位置
把A[1][mid]贴两遍(套路)
枚举A[mid+1][lenA]在A[1][mid]中出现的位置,把其他位置的hash值求出来,在map里查有多少符合的B串
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<map>
- #include<algorithm>
- using namespace std;
- const int maxn=8000009;
- typedef unsigned long long uLint;
- int n,m,lenA,lenB,mid;
- char s[maxn];
- long long ans;
- int r;
- uLint h[maxn];
- uLint fac[maxn];
- map<uLint,int>ma;
- uLint a[maxn];
- void Addstring(){
- int cnt=0;
- uLint midstring=0;
- for(int i=mid+1;i<=lenA;++i)midstring=midstring*233+s[i];
- for(int i=1;i<=mid;++i)s[i+mid]=s[i];
- h[0]=0;
- for(int i=1;i<=mid+mid;++i)h[i]=h[i-1]*233+s[i];
- for(int i=1;i<=mid;++i){
- uLint tm=h[i+r-1]-h[i-1]*fac[r];
- if(tm!=midstring)continue;
- a[++cnt]=h[i+mid-1]-h[i+r-1]*fac[mid-r];
- }
- sort(a+1,a+1+cnt);
- cnt=unique(a+1,a+1+cnt)-a-1;
- for(int i=1;i<=cnt;++i)ma[a[i]]++;
- }
- int main(){
- scanf("%d%d%d%d",&n,&m,&lenA,&lenB);
- fac[0]=1;
- for(int i=1;i<=lenA+lenA;++i)fac[i]=fac[i-1]*233;
- mid=(lenA+lenB)>>1;
- r=lenA-mid;
- while(n--){
- scanf("%s",s+1);
- Addstring();
- }
- while(m--){
- scanf("%s",s+1);
- uLint tm=0;
- for(int i=1;i<=lenB;++i)tm=tm*233+s[i];
- ans=ans+ma[tm];
- }
- cout<<ans<<endl;
- return 0;
- }
BZOJ 4084 [Sdoi2015]双旋转字符串的更多相关文章
- [bzoj4084][Sdoi2015]双旋转字符串_hash
双旋转字符串 bzoj-4084 Sdoi-2015 题目大意:给定两个字符串集合 S 和 T .其中 S 中的所有字符串长度都恰好为 N ,而 T 中所有字符串长度都恰好为 M .且 N+M 恰好为 ...
- bzoj 4084 双旋转字符串
给两个集合A,B,找满足要求的(a,b)的对数,可以计算对于a,哪些b成立. 还有就是字符串hash的使用,感觉平时用字符串hash太少了. /**************************** ...
- 【bzoj4084】【sdoi2015】双旋转字符串
题解 首先题中说了$n>=m$; 分成的循环串左右两边为本质相同的单循环串循环串,分别长为$l = \frac{n + m}{2} $; 所以$S$串的前$l$位为双循环串的一半$S1$,后一半 ...
- 剑指Offer面试题:34.翻转单词顺序VS左旋转字符串
一.题目一:翻转单词顺序 1.1 题目说明 题目一:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.为简单起见,标点符号和普通字母一样处理.例如输入字符串"I am a st ...
- 【面试题042】翻转单词顺序VS左旋转字符串
[面试题042]翻转单词顺序VS左旋转字符串 题目一: 输入一个英文句子,反转句子中单词的顺序,但单词内字符的顺序不变.为简单起见,标点符号和普通字母一样处理. 例如输入字符串“I a ...
- lintcode :旋转字符串
题目: 旋转字符串 给定一个字符串和一个偏移量,根据偏移量旋转字符串(从左向右旋转) 样例 对于字符串 "abcdefg". offset=0 => "abcdef ...
- 九度OJ 1362 左旋转字符串(Move!Move!!Move!!!)【算法】
题目地址:http://ac.jobdu.com/problem.php?pid=1362 题目描述: 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运 ...
- LintCode 面试题 旋转字符串
1.题目描述 题目链接:http://www.lintcode.com/zh-cn/problem/rotate-string/ 给定一个字符串和一个偏移量,根据偏移量旋转字符串(从左向右旋转) 2. ...
- 1289 大鱼吃小鱼 1305 Pairwise Sum and Divide 1344 走格子 1347 旋转字符串 1381 硬币游戏
1289 大鱼吃小鱼 有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右.游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼.从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右 ...
随机推荐
- spring-页面模板配置
一个可用的freemaker配置: ... @Bean public ViewResolver viewResolver() { FreeMarkerViewResolver fr = new Fre ...
- STM32之GD25Q256应用笔记
前言 使用标准SPI指令格式: 3字节地址模式或4字节地址模式: 支持SPI 总线 模式0 和 模式3: 存储容量32MB: 时钟频率范围:80Mhz – 104Mhz: 主机:STM32F103ZE ...
- G. Repeat it
G. Repeat it time limit per test 2.0 s memory limit per test 64 MB input standard input output stand ...
- VC 插入excel
CString ePath,iPath; m_ePath.GetWindowText(ePath); m_iPath.GetWindowText(iPath); _Application app; W ...
- 【pwnable.kr】blackjack
又一道pwnable nc pwnable.kr 9009 读题找到源代码在:http://cboard.cprogramming.com/c-programming/114023-simple-bl ...
- 使用git提交远程仓库
git pull 更新 git add 文件名 将文件添加到暂存区 git commit -m ‘注释’ 提交 git push origin master 提交到远程仓库
- SpringMVC原理及流程解析
前言 春节期间宅在家里闲来无事,对SpringMVC进行了比较深入的了解,将之前模糊不清的地方基本摸索清楚了,特此撰文总结记录一下. 正文 一.一个请求为什么会调用到SpringMVC框架里? 首先问 ...
- 三十、SAP中的内置图标
一.选择[编辑]->[模式] 二.选中写入模式 三.选中图标 四.选择我们需要的图标 五.选中图标后,选择复制 六.点击之后,会回到代码界面,如下 七.执行结果如下,显示出了一个神奇的图标
- 115-PHP实例化和不实例化输出类常量
<?php class boy{ //定义男孩类 const sex='男'; public $age=15; } echo '不实例化对象输出类常量:'.boy::sex; $boy=new ...
- 计算方法执行完的耗时 c#
Stopwatch watch = Stopwatch.StartNew(); //要执行的方法 test(); watch.Stop(); Console.WriteLine(string.Form ...