Codeforces Round #215 (Div. 1) B. Sereja ans Anagrams 匹配
B. Sereja ans Anagrams
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/367/B
Description
Sereja needs to rush to the gym, so he asked to find all the described positions of q.
Input
The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands.
Then
follow n lines, each contains one command. Each of these lines contains
either command pwd, or command cd, followed by a space-separated
non-empty parameter.
The command parameter cd only contains lower
case Latin letters, slashes and dots, two slashes cannot go
consecutively, dots occur only as the name of a parent pseudo-directory.
The command parameter cd does not end with a slash, except when it is
the only symbol that points to the root directory. The command parameter
has a length from 1 to 200 characters, inclusive.
Directories in the file system can have the same names.
Output
The first line contains three integers n, m and p (1 ≤ n, m ≤ 2·105, 1 ≤ p ≤ 2·105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109).
Sample Input
5 3 1
1 2 3 2 1
1 2 3
Sample Output
2
1 3
HINT
题意
给你n个a[i],m个b[i],和P
要求让你找到起点,使得a[pos],a[pos+p],a[pos+2*p]……,a[pos+(m-1)*p]和b数组一样
题解:
类似于km算法
我们把b[i]表示为子串
a[i]表示为母串
因为不要求顺序,我们就直接跑就好了,只要匹配不是O(m*n)的都能过吧
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1050005
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int a[maxn];
int b[maxn];
map<int,int> H;
map<int,int> H1;
vector<int> ans;
int main()
{
int n=read(),m=read(),p=read();
for(int i=;i<=n;i++)
a[i]=read();
for(int i=;i<=m;i++)
b[i]=read(),H[b[i]]++;
int pos;
int flag=;
for(int i=;i<=p;i++)
{
H1.clear(),pos=i,flag=;;
for(int j=i;j<=n;j+=p)
{
H1[a[j]]++,flag++;;
if(H1[a[j]]>H[a[j]])
{
for(int k=pos;k<=j;k+=p)
{
H1[a[k]]--,flag--;
if(a[j]==a[k])
{
pos=k+p;
break;
}
}
continue;
}
if(flag==m)
{
ans.push_back(pos);
H1[a[pos]]--;
flag--;
pos+=p;
}
}
}
sort(ans.begin(),ans.end());
cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++)
printf("%d ",ans[i]); }
Codeforces Round #215 (Div. 1) B. Sereja ans Anagrams 匹配的更多相关文章
- Codeforces Round #215 (Div. 2) D. Sereja ans Anagrams
http://codeforces.com/contest/368/problem/D 题意:有a.b两个数组,a数组有n个数,b数组有m个数,现在给出一个p,要你找出所有的位置q,使得位置q q+ ...
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map
B. Sereja and Suffixes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- Codeforces Round #215 (Div. 2) C. Sereja and Algorithm
#include <iostream> #include <vector> #include <algorithm> #include <string> ...
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
#include <iostream> #include <vector> #include <algorithm> #include <set> us ...
- Codeforces Round #215 (Div. 2) A. Sereja and Coat Rack
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #215 (Div. 2) D题(离散化+hash)
D. Sereja ans Anagrams time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #215 (Div. 1)
A Sereja and Algorithm 题意:给定有x,y,z组成的字符串,每次询问某一段s[l, r]能否变成变成zyxzyx的循环体. 分析: 分析每一段x,y,z数目是否满足构成循环体,当 ...
- Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并
题目链接:http://codeforces.com/contest/381/problem/E E. Sereja and Brackets time limit per test 1 secon ...
- Codeforces Round #223 (Div. 2)--A. Sereja and Dima
Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- Delphi 提示在Delphi的IDE中,按Ctrl+Shift+G键可以为一个接口生成一个新的GUID。
对于Object Pascal语言来说,最近一段时间最有意义的改进就是从Delphi3开始支持接口(interface),接口定义了能够与一个对象进行交互操作的一组过程和函数.对一个接口进行定义包含两 ...
- 从高铁G18中高端如厕看12306的验证码
1.引子 最近疯狂的吐槽12306网站的虐心验证码. 从对铁老大的一贯作风来说,这个事不过是芝麻绿豆的事情.这个事件只是因为发生在网络上,而引起了广大网民的一致谴责而已. 相信更丰富的如厕经历,大家只 ...
- c/c++ 数字转成字符串, 字符串转成数字
c/c++ 数字转成字符串, 字符串转成数字 ------转帖 数字转字符串: 用C++的streanstream: #include <sstream> #Include <str ...
- 千万别把js的正则表达式方法和字符串方法搞混淆了
我们在字符串操作过程中肯定经常用了test() split() replace() match() indexof()等方法,很多人经常把用法写错了,包括我,所以今天细细的整理了下. test()是判 ...
- [转] 请别再拿“String s = new String("xyz");创建了多少个String实例”来面试了吧
这帖是用来回复高级语言虚拟机圈子里的一个问题,一道Java笔试题的. 本来因为见得太多已经吐槽无力,但这次实在忍不住了就又爆发了一把.写得太长干脆单独开了一帖. 顺带广告:对JVM感兴趣的同学们同志们 ...
- 使用nodejs中httpProxy代理时候出现404异常
在公司中使用nodejs构建代理服务器实现前后台分离,代码不能拿出来,然后出现httpProxy代理资源的时候老是出现404.明明被代理的接口是存在的.代码大概如下: var http = requi ...
- JavaWeb高性能开发(一)
今日要闻: 淘宝删差评产业链 在你给出"差评""中评"后不久,有人会偷偷登录你的淘宝账户,把你之前给过的评价删除或改成"好评".而这种人就是 ...
- [POJ] #1008# Maya Calendar : 字符处理/同余问题
一. 题目 Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 74085 Accepted: 2 ...
- 通过网络方式安装linux的五种方法
在线观看:http://video.sina.com.cn/v/b/43086503-1443650204.html http://video.sina.com.cn/v/b/43095530-144 ...
- django1.77+mod_wsgi+python2.79+apache2.24 在阿里云centos部署攻略
心平气和的记录一下今天 踩的坑以防万一 以后还踩 首先我今天的平台是在 阿里云上的一台纯净版的 centos6.5 64位主机上进行的 首先装python2.7 去官网下载python2.7安装包 然 ...