思路:

kmp + 二分。

实现:

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN = ;
int neXt[MAXN]; void getNext(string s)
{
int n = s.length();
neXt[] = -;
int k = -, j = ;
while (j < n)
{
if (k == - || s[j] == s[k])
{
j++; k++;
if (s[j] != s[k]) neXt[j] = k;
else neXt[j] = neXt[k];
}
else
{
k = neXt[k];
}
}
} int kmp(string s, string p)
{
int i = , j = ;
int m = s.length(), n = p.length();
while (i < m && j < n)
{
if (j == - || s[i] == p[j]) i++, j++;
else j = neXt[j];
}
if (j == n) return i - j;
return -;
} bool solve(string x, string y, vector<pair<int, int>> & ans)
{
string z(x);
reverse(z.begin(), z.end());
int m = x.length();
int n = y.length();
int start = ;
while (start < n)
{
int l = , r = n - start, res = , pos = -;
bool flg = true;
while (l <= r)
{
int mid = (l + r) >> ;
string tmp = y.substr(start, mid);
getNext(tmp);
int p = kmp(x, tmp);
if (p != -)
{
res = mid; pos = p; flg = true; l = mid + ;
}
else if ((p = kmp(z, tmp)) != -)
{
res = mid; pos = p; flg = false; l = mid + ;
}
else r = mid - ;
}
if (!res) return false;
if (flg) ans.push_back(pair<int, int>(pos + , pos + res));
else ans.push_back(pair<int, int>(m - pos, m - pos - res + ));
start += res;
}
return true;
} int main()
{
string x, y;
cin >> x >> y;
vector<pair<int, int>> res;
if (solve(x, y, res))
{
cout << res.size() << endl;
for (int i = ; i < res.size(); i++)
cout << res[i].first << " " << res[i].second << endl;
}
else
{
puts("-1");
}
return ;
}

CF615C Running Track的更多相关文章

  1. Codeforces Round #338 (Div. 2) C. Running Track dp

    C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...

  2. 【28.57%】【codeforces 615C】 Running Track

    time limit per test1 second memory limit per test512 megabytes inputstandard input outputstandard ou ...

  3. Codeforces 615C Running Track(DP + Trie树)

    题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. ...

  4. Codeforces Round #338 (Div. 2)

    水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...

  5. 基于智能手机的3D地图导航

    https://www.gpsworld.com/resources/archives/ Going 3D Personal Nav and LBS To enrich user experience ...

  6. 智课雅思词汇---十二、vent是什么意思

    智课雅思词汇---十二.vent是什么意思 一.总结 一句话总结:词根:ven, vent = come, 表示“来” 词根:vent = wind 风 1.tact是什么意思? 词根:-tact-, ...

  7. POJ 题目3661 Running(区间DP)

    Running Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5652   Accepted: 2128 Descripti ...

  8. Running Kafka At Scale

    https://engineering.linkedin.com/kafka/running-kafka-scale If data is the lifeblood of high technolo ...

  9. Running a Remote Desktop on a Windows Azure Linux VM (远程桌面到Windows Azure Linux )-摘自网络(试了,没成功 - -!)

                              A complete click-by-click, step-by-step video of this article is available ...

随机推荐

  1. 【Codeforces 501C】Misha and Forest

    [链接] 我是链接,点我呀:) [题意] 给你一棵树 但是每个节点只告诉你出度个数 以及所有和它相连的点的异或和. 让你还原这棵树 [题解] 叶子节点的话,他所有节点的异或和就是它那唯一的一个爸爸 因 ...

  2. Oracle操作管理之用户和角色

    1.用户管理 (1)建立用户(数据库验证) CREATE USER smith IDENTIFIED BY smith_pwd DEFAULTTABLESPACE users TEMPORARY TA ...

  3. ORA-12541:TNS:无监听程序

    安装oracle以后,sql plus可以正常登陆,pl/sql登陆时报错ORA-12541:TNS:无监听程序,解决方案如下: http://blog.csdn.net/hao134838/arti ...

  4. [bzoj1613][Usaco2008 Jan]Running贝茜的晨练计划_动态规划

    Running贝茜的晨练计划 bzoj-1613 Usaco-2008 Jan 题目大意:题目链接(U组题题意真的是没法概括qwq....). 注释:略. 想法:一眼dp题. 状态:dp[i][j]表 ...

  5. T1002 搭桥 codevs

    http://codevs.cn/problem/1002/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 有一矩形区域的城 ...

  6. docker重新打包MySQL5.7镜像

    1:先下载MySQL镜像 # docker pull  mysql:5.7   2:运行镜像生成容器 # docker run --name mysql -p 3306:3306 -e MYSQL\_ ...

  7. zabbix全方位监控MySQL +cacti监控mysql

    http://www.linuxidc.com/Linux/2015-02/112690.htm http://john88wang.blog.51cto.com/2165294/1596272?ut ...

  8. 程序员之---C语言细节20(符号和有符号之间转换、两数相加溢出后数值计算)

    主要内容:无符号和有符号之间转换.两数相加溢出后数值计算 #include <stdio.h> /* 这个函数存在潜在漏洞 */ float sum_elements(float a[], ...

  9. ZOJ 3201

    id=15737" target="_blank">Tree of Tree Time Limit: 1000MS   Memory Limit: 32768KB ...

  10. 写给小白的JVM学习指南

    Java 虚拟机是学习 Java 的基础,也是迈入高级 Java 开发工程师的必备知识点.所以今天这篇文章我们来聊聊如何从零开始学习 Java 虚拟机. 基础 对于刚刚接触 JVM 的同学来说,JVM ...