题目链接:http://codeforces.com/gym/101466/problem/E

题目:

题意:

  给你s串和t串,一个数k,求t的最长前缀串在s串中出现次数不少于k。

思路:

  一眼二分+kmp,二分最长前缀串的长度即可。

代码实现如下:

 #include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;;
typedef pair<int, int> pii;
typedef unsigned long long ull; #define lson i<<1
#define rson i<<1|1
#define lowbit(x) x&(-x)
#define bug printf("*********\n");
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define FIN freopen("D://code//in.txt", "r", stdin);
#define IO ios::sync_with_stdio(false),cin.tie(0); const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = 1e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f; int k, lens1, lens2, ans, num;
char s1[maxn], s2[maxn];
int nex[maxn]; void get_next() {
nex[] = ;
for(int i = , j = ; i <= lens2; i++) {
while(j > && s2[i] != s2[j+]) j = nex[j];
if(s2[i] == s2[j+]) j++;
nex[i] = j;
}
} void kmp() {
get_next();
for(int i = , j = ; i <= lens1; i++) {
while(j > && (j == lens2 || s1[i] != s2[j+])) j = nex[j];
if(s1[i] == s2[j+]) j++;
if(j == lens2) {
num++;
}
}
} bool check(int x) {
lens2 = x;
num = ;
kmp();
return num >= k;
} int main() {
fgets(s1 + , maxn, stdin);
fgets(s2 + , maxn, stdin);
scanf("%d", &k);
lens1 = strlen(s1 + ), lens2 = strlen(s2 + );
int ub = lens2, lb = , mid;
ans = ;
while(ub >= lb) {
mid = (ub + lb) >> ;
if(check(mid)) {
ans = mid;
lb = mid + ;
} else {
ub = mid - ;
}
}
if(ans > ) {
for(int i = ; i <= ans; i++) {
printf("%c", s2[i]);
}
printf("\n");
}
else printf("IMPOSSIBLE\n");
return ;
}

E.Text Editor (Gym 101466E + 二分 + kmp)的更多相关文章

  1. Rich Text Editor for MVC

    在网站开发中难免会用到富文本编辑器,本文将介绍一款富文本编辑器(在线HTML编辑器) Rich Text Editor ,简要说明一下其在MVC中的使用. 具体使用情况和下载地址请参考:http:// ...

  2. Android开展:ADT+Eclipse使用错误:Text editor does not have a document provider

    Eclipse参加Android sdk源代码 正在使用Eclipse进行Android开发时间,我们经常需要导入sdk源代码来Eclipse中,方便api阅读和查询,详细操作为:ctrl+鼠标左键. ...

  3. web & Rich Text Editor

    web & Rich Text Editor 富文本编辑器 http://www.wangeditor.com/ https://github.com/wangfupeng1988/wangE ...

  4. DevExpress ASP.NET Core v19.1版本亮点:Rich Text Editor

    行业领先的.NET界面控件DevExpress 发布了v19.1版本,本文将以系列文章的方式为大家介绍DevExpress ASP.NET Core Controls v19.1中新增的一些控件及增强 ...

  5. Download EditPlus Text Editor

    突然发现EditPlus还是很强大的,很好用,破解也很方便,有个牛人做了在线生成验证码,只能说服!! 下边把官网的最新下载地址贴出,当然还有在线生成验证码喽. EditPlus Text Editor ...

  6. 【贪心】【后缀自动机】Gym - 101466E - Text Editor

    题意:给你两个串A,B,以及一个整数K,让你找到B的一个尽可能长的前缀,使得其在A串中出现的次数不小于K次. 对A串建立后缀自动机,然后把B串放在上面跑,由于每到一个结点,该结点endpos集合的大小 ...

  7. CHtmlEditCtrl (2): Add a Source Text Editor to Your HTML Editor

    In a previous article, I described how to create an HTML editor using the MFC CHtmlEditCtrl class in ...

  8. Gym - 100989G 二分

    链接:ECJTU 2018 Summer Training 1 - Virtual Judge  https://vjudge.net/contest/236677#problem/G 谷歌翻译: 距 ...

  9. Gym - 101908G 二分答案+最大流

    After the end of the truck drivers' strike, you and the rest of Nlogônia logistics specialists now h ...

随机推荐

  1. spring重定向与转发

    1.重定向 A,通过ModelAndView以及RedirectView @RequestMapping("/login1.do") public ModelAndView log ...

  2. (十一)Jmeter另一种调试工具 HTTP Mirror Server

    之前我介绍过Jmeter的一种调试工具Debug Sampler,它可以输出Jmeter的变量.属性甚至是系统属性而不用发送真实的请求到服务器.既然这样,那么HTTP Mirror Server又是做 ...

  3. html5兼容

    You can download the latest version of HTML5shiv from github or reference the CDN version at https:/ ...

  4. django里的http协议

    一个普通的user Begin########## ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__' ...

  5. idea导出包含main函数的jar

    1.首先打开File->project stucture->Artifacts 2.按照下图方式: 3.选择面main函数的所在的类,选择MAINFEST.MF问的生成路径 这里一定选择 ...

  6. 【前端学习笔记05】JavaScript数据存储Cookie相关方法封装

    //Cookie设置 //设置新cookie function setCookie(name,value,duration){ var date = new Date(); date.setTime( ...

  7. 第146天:移动H5前端性能优化

    移动H5前端性能优化 一.概述 1. PC优化手段在Mobile侧同样适用 2. 在Mobile侧我们提出三秒种渲染完成首屏指标 3. 基于第二点,首屏加载3秒完成或使用Loading 4. 基于联通 ...

  8. HttpHandler与HttpModule的理解与应用

    问题1:什么是HttpHandler? 问题2:什么是HttpModule? 问题3:什么时候应该使用HttpHandler什么时候使用HttpModule? 答案1:HttpHandler,Http ...

  9. Proving Equivalences UVALive - 4287(强连通分量 水题)

    就是统计入度为0 的点 和 出度为0 的点  输出 大的那一个,, 若图中只有一个强连通分量 则输出0即可 和https://www.cnblogs.com/WTSRUVF/p/9301096.htm ...

  10. php扩展库 说明

    1 zlib是提供数据压缩用的函式库, 2 libxml2 Libxml2 is the XML C parser and toolkit developed for the Gnome projec ...