题目链接: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. mysql子查询批量找id最大的

    $sql = "select a.id as max_id,a.uid from(SELECT `uid`, idFROM (`users_level_change_log`)WHERE ` ...

  2. 31. Ubuntu15.04系统中如何启用、禁用客人会话

    https://jingyan.baidu.com/article/046a7b3edf9639f9c27fa995.html 31. Ubuntu15.04系统中如何启用.禁用客人会话 听语音 | ...

  3. (转)用MongoDB 实现优酷API 缓存

    由于众所周知的原因, 邪恶的企业优酷于九月的某一天开始禁止第三方播放器加载视频API, 我不得不设置一个反向代理来绕过Flash 的跨域限制. 自此服务器压力激增, 导致用户体验大为劣化. 为了减少服 ...

  4. 关于command 'gcc' failed with exit status 1 解决方法

    Python踩坑之路 Setup script exited with error: command 'gcc' failed with exit status 1 由于没有正确安装Python开发环 ...

  5. TP中if标签

    if标签 If标签如果php中if语句的作用,if是用于流程控制的. 在ThinkPHP中if标签也是用于流程控制的. If标签的语法格式: <if condition=’条件表达式’> ...

  6. linux普通用户被内存被限制的问题

    把应用从root用户迁移到普通用户test,由于普通用户会被限制最大的进程数,当进程数占满后出现了下面的错误 /bin/bash: Resource temporarily unavailable. ...

  7. 第80天:jQuery插件使用

    jQuery其他补充+ 4.1 链式编程: end()补充 * 补充五角星 评论案例 * 第一步:鼠标移入,当前五角星和前面的五角星变实体.后面的变空心五角星 * 第二步:鼠标点击的时候,为当前元素添 ...

  8. AtCoder Grand Contest 019 B: Reverse and Compare

    题意: 给出一个字符串,你可以选择一个长度大于等于1的子串进行翻转,也可以什么都不做.只能翻转最多一次. 问所有不同的操作方式得到的字符串中有多少个是本质不同的. 分析 tourist的题妙妙啊. 首 ...

  9. OGG内部进程介绍

    1.首先看看什么是OGG,以及OGG的用途       简单的来讲 Oracle Golden Gate (简称OGG)是一种基于日志的结构化数据复制备份软件,它通过解析源数据库在线日志或归档日志获得 ...

  10. bug:margin合并

    demo1和demo2存在margin合并问题:外边距合并指的是,当两个垂直外边距相遇时,它们将形成一个外边距.合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者.弥补方案:bfc; 添加一 ...