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 ...
随机推荐
- BITMAP CONVERSION FROM ROWIDS
在有些执行计划中,可以会看到 BITMAP CONVERSION FROM ROWIDS这样的东东,也许你会感觉奇怪,我没有使用位图索引怎么出现了bitmap.我通过一个sql和大家分析下原因:sql ...
- 运行Python2.x程序报编码错误的解决办法-UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordina not in range(128)[0m
Python编码问题的终极解决方案:在python的Lib\site-packages文件夹下新建一个sitecustomize.py文件,输入: import sys sys.setdefaulte ...
- 【LeetCode】228 - Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- leetcode刷题总结一
大四狗找工作,要刷题了,leetcode上面题目比较适合面试算法类题目,也不纯粹为了蒙题,锻炼一下面试类型的思维 Single Number: 有N个数,其中只有一个数出现了一次,其他都是两次,找出那 ...
- ASP.NET下跨应用共享Session和使用Redis进行Session托管简介
在之前的博客中,我说到了Session的共享问题,其中说到了Web Farm和Web Garden两种情况下Session的处理.在ASP.NET提供的Session处理方法中,有以下四种模式: 1. ...
- Xcode集成Google Test
Xcode集成Google Test 1.下载源代码https://github.com/google/googletest 2.进入下载文件目录下googletest/make中运行make gte ...
- cocos2d-js取不到cocostudio里面控件问题
var winSize = cc.director.getWinSize(); //add main node var mainNode = cc.Node.create(); ; mainNode. ...
- 记录一个 关于 python 普通方法,静态方法和类方法 的介绍。@classmethod @staticmethod
上班时间 只贴看到最厉害的答案 回头总结 http://stackoverflow.com/questions/12179271/python-classmethod-and-staticmethod ...
- 【全面完美方案】iPhone 4S WiFi变灰 DIY修复方式
这是我在一位台湾网友usaretama发表的一篇帖子中看到的,原帖我发表在维维网 如果你有WiFi开关变灰不能切换.WiFi遇到搜不到AP或搜到了连不上,那您就要注意这篇了. 家人的 iPhone 4 ...
- HDU 3364 Lanterns (高斯消元)
题意:有n个灯和m个开关,每个开关控制数个灯的状态改变,给出k条询问,问使灯的状态变为询问中的状态有多少种发法. 析:同余高斯消元法,模板题,将每个开关控制每个灯列成行列式,最终状态是结果列,同余高斯 ...