E.Text Editor (Gym 101466E + 二分 + kmp)
题目链接: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)的更多相关文章
- Rich Text Editor for MVC
在网站开发中难免会用到富文本编辑器,本文将介绍一款富文本编辑器(在线HTML编辑器) Rich Text Editor ,简要说明一下其在MVC中的使用. 具体使用情况和下载地址请参考:http:// ...
- Android开展:ADT+Eclipse使用错误:Text editor does not have a document provider
Eclipse参加Android sdk源代码 正在使用Eclipse进行Android开发时间,我们经常需要导入sdk源代码来Eclipse中,方便api阅读和查询,详细操作为:ctrl+鼠标左键. ...
- web & Rich Text Editor
web & Rich Text Editor 富文本编辑器 http://www.wangeditor.com/ https://github.com/wangfupeng1988/wangE ...
- DevExpress ASP.NET Core v19.1版本亮点:Rich Text Editor
行业领先的.NET界面控件DevExpress 发布了v19.1版本,本文将以系列文章的方式为大家介绍DevExpress ASP.NET Core Controls v19.1中新增的一些控件及增强 ...
- Download EditPlus Text Editor
突然发现EditPlus还是很强大的,很好用,破解也很方便,有个牛人做了在线生成验证码,只能说服!! 下边把官网的最新下载地址贴出,当然还有在线生成验证码喽. EditPlus Text Editor ...
- 【贪心】【后缀自动机】Gym - 101466E - Text Editor
题意:给你两个串A,B,以及一个整数K,让你找到B的一个尽可能长的前缀,使得其在A串中出现的次数不小于K次. 对A串建立后缀自动机,然后把B串放在上面跑,由于每到一个结点,该结点endpos集合的大小 ...
- 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 ...
- Gym - 100989G 二分
链接:ECJTU 2018 Summer Training 1 - Virtual Judge https://vjudge.net/contest/236677#problem/G 谷歌翻译: 距 ...
- Gym - 101908G 二分答案+最大流
After the end of the truck drivers' strike, you and the rest of Nlogônia logistics specialists now h ...
随机推荐
- 1029C语言文法的理解
<程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...
- [学习]WireShark 的过滤功能
1. 打开 wireShark 过滤显示 协议 比如显示arp协议 过滤栏输入arp即可 支持的协议类型 TCP UDP HTTP FTP ICMP SMTP等等 2. 过滤ip地址 ip.addr ...
- [讲解]sql except和intersect运算符(比拟两个或多个select语句的结果并前去非重复值)
图 1 UNION 中若有重复的行,会被移除,只留下一个 1.简介 EXCEPT和INTERSECT运算符使您可以比较两个或多个SELECT语句的结果并返回非重复值. 2.区别 EXCEPT运算符返回 ...
- Ubuntu的IP地址配置
概况和需求: 我的主机上有两块网卡,识别后分别是eth0和eth1.eth0配置需要为静态ip,eth1配置为使用动态主机协议获取ip地址. 步骤: 首先碰到的一个问题就是不知道eth0和eth1对应 ...
- 【C++】深度探索C++对象模型读书笔记--关于对象(Object Lessons)
前言中的内容: 1.什么是C++对象模型? 1.语言中直接支持面向对象程序设计的部分 2. 对于各种支持的底层实现机制 2. C++ class的完整virtual functions在编译时期就固定 ...
- 第200天:js---常用string原型扩展
一.常用string原型扩展 1.在字符串末尾追加字符串 /** 在字符串末尾追加字符串 **/ String.prototype.append = function (str) { return t ...
- 【明哥报错簿】之【 "javax.servlet.http.HttpServlet" was not found on the Java Build Path || HttpServletRequest/HttpServletResponse cannot be resolved to a type】
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path login ...
- The Necklace UVA - 10054(欧拉回路)
题目分析:1.无向图欧拉回路是否连通2.所有点的度为偶数.并查集+degree 这题题目保证了是联通的 所以就不用判断是否联通了 #include <iostream> #include ...
- 【MediaElement】WPF视频播放器【1】
一.前言 前两天上峰要求做一个软件使用向导,使用WPF制作.这不,这两天从一张白纸开始学起,做一个播放演示视频的使用向导.以下是粗设计的原型代码: 二.效果图 三.代码 前台代码: < ...
- Codeforces707Div2
A Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was ups ...