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 ...
随机推荐
- As3 计算两个日期之间的天数差
/*日期转YYYYMMDD*/ formDate.fullYear+""+(formDate.month<10?("0"+formDate.month): ...
- LR之脚本调试
1.概述 2.Animated run和Non-animated run 3.调试小技巧 4.日志设置
- LR 解决中文乱码(来源——百度)
因为我们使用的中文操作系统默认的中文编码格式是GB2312,所以LR对服务器的返回内容自动使用GB2312方式阅读的,但是几乎所有的中文网站现在都在使用UTF-8的方式来编码,由于解码编码的方式不同最 ...
- Cocos2d-android (04) 执行多个动作
先后.同时执行多个动作及动作序列执行结束后的事件 import org.cocos2d.actions.instant.CCCallFunc; import org.cocos2d.actions.i ...
- 静态成员变量.xml
pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...
- 【LeetCode】38 - Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- 图算法之Floyd-Warshall 算法-- 任意两点间最小距离
1.Floyd-Warshall 算法 给定一张图,在o(n3)时间内求出任意两点间的最小距离,并可以在求解过程中保存路径 2.Floyd-Warshall 算法概念 这是一个动态规划的算法. 将顶点 ...
- 【24点游戏】cocos2dx 源码
1. 4个数字 24点判断 double Calc(double a, double b, string oper) { double result = 0; const char *p = ope ...
- Python:数字
一.数字简介 数字可以直接访问,是不可更改并且不可分割的原子类型,这些在标准类型的分类中都谈到了.不可更改意味着变更数字值的实质是新对象的创建.当然,这些对于程序员来说都是透明的,不需过多考虑. 1. ...
- 第二百二十九天 how can I 坚持
百度-让人更容易的获取信息,腾讯-让人更方便的交流,阿里-让人更方便的消费,每个公司都有自己的使命,每个公司的使命都是围绕着人. 创新-其实应该是在每个人的内心深处都或多或少有一些新的想法,但是什么是 ...