题目链接: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. (双人项目)四则运算 组员:杨钰宁 闫浩楠 开发语言:Python。

    需求分析:1.适用人群:小学生. 2.能进行“+,—,*,/” 的四则运算.难度可以随时修改. 3.提交试卷后可以显示所得分数并显示错题个数. 4.可以显示答对的题及其打错的题的序号. 代码如下: i ...

  2. vue-cli3使用 DllPlugin 实现预编译,提升构建速度

    在项目打包上有两个目标:减少打包代码体积和加快打包速度 1. 减少打包体积: (1)对于用的比较少的库,可以去掉(我去掉了jquery以及lodash),用到的地方,参考源码自己写 (2)非用不可的又 ...

  3. Linux服务器启动后只读解决办法

    今天处理一个服务器,远程死活连接不上,只好跑信息中心去看了下服务器. Linux服务器启动之后,提示: give root password for maintenance (or type cont ...

  4. layabox 3d 入手

    最近受到打击了,3d效果远比2d效果好. 问题 laya3d 有正交相机没有? Laya.Sprite3D.load(XX.lh);   克隆Laya.Sprite3D.instantiate Lay ...

  5. BZOJ 1853 幸运数字(容斥原理+dfs)

    题意:求闭区间内能被6和8组成的数字整除的数目.n<=1e11. 我们可以预处理出这些6和8组成的数字,大概2500个,然后排除一些如88,66的情况.这样大概还剩下1000个. 转化为[0,r ...

  6. python写BMI指数菜单

    需求: # 1.创建并输出菜单, 菜单是不可变的. 所以使用元组menus = ("1, 录入", "2, 查询", "3, 删除", &q ...

  7. [二十三]SpringBoot 之 redis

    本文章牵涉到的技术点比较多:spring Data JPA.Redis.Spring MVC,Spirng Cache,所以在看这篇文章的时候,需要对以上这些技术点有一定的了解或者也可以先看看这篇文章 ...

  8. static变量的特点 - 只会有一份成员对象

    1.   public class HasStatic{ 2.     private static int x=100; 3.     public static void main(String ...

  9. 【容斥原理,莫比乌斯反演】用容斥替代莫比乌斯反演第二种形式解决gcd统计问题

    名字虽然很长.但是其实很简单,对于这一类问题基本上就是看你能不能把统计的公式搞出来(这时候需要一个会推公式的队友) 来源于某次cf的一道题,盼望上紫的我让潘学姐帮我代打一道题,她看了看跟我说了题解,用 ...

  10. 行列式(二):余子式&代数余子式

    目录 按行列展开 \(\Delta\)以下内容主要为<线性代数>的学习笔记 按行列展开 一般来说,低阶行列式的计算比高阶行列式的计算要简单得多,因此考虑用低阶行列式来表示高阶行列式.为此, ...