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

题目:

题意:

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

思路:

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

代码实现如下:

 1 #include <set>
 2 #include <map>
 3 #include <queue>
 4 #include <stack>
 5 #include <cmath>
 6 #include <bitset>
 7 #include <cstdio>
 8 #include <string>
 9 #include <vector>
10 #include <cstdlib>
11 #include <cstring>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15
16 typedef long long ll;
17 typedef pair<ll, ll> pll;
18 typedef pair<ll, int> pli;
19 typedef pair<int, ll> pil;;
20 typedef pair<int, int> pii;
21 typedef unsigned long long ull;
22
23 #define lson i<<1
24 #define rson i<<1|1
25 #define lowbit(x) x&(-x)
26 #define bug printf("*********\n");
27 #define debug(x) cout<<"["<<x<<"]" <<endl;
28 #define FIN freopen("D://code//in.txt", "r", stdin);
29 #define IO ios::sync_with_stdio(false),cin.tie(0);
30
31 const double eps = 1e-8;
32 const int mod = 1e9 + 7;
33 const int maxn = 1e5 + 7;
34 const double pi = acos(-1);
35 const int inf = 0x3f3f3f3f;
36 const ll INF = 0x3f3f3f3f3f3f3f3f;
37
38 int k, lens1, lens2, ans, num;
39 char s1[maxn], s2[maxn];
40 int nex[maxn];
41
42 void get_next() {
43     nex[1] = 0;
44     for(int i = 2, j = 0; i <= lens2; i++) {
45         while(j > 0 && s2[i] != s2[j+1]) j = nex[j];
46         if(s2[i] == s2[j+1]) j++;
47         nex[i] = j;
48     }
49 }
50
51 void kmp() {
52     get_next();
53     for(int i = 1, j = 0; i <= lens1; i++) {
54         while(j > 0 && (j == lens2 || s1[i] != s2[j+1])) j = nex[j];
55         if(s1[i] == s2[j+1]) j++;
56         if(j == lens2) {
57             num++;
58         }
59     }
60 }
61
62 bool check(int x) {
63     lens2 = x;
64     num = 0;
65     kmp();
66     return num >= k;
67 }
68
69 int main() {
70     fgets(s1 + 1, maxn, stdin);
71     fgets(s2 + 1, maxn, stdin);
72     scanf("%d", &k);
73     lens1 = strlen(s1 + 1), lens2 = strlen(s2 + 1);
74     int ub = lens2, lb = 0, mid;
75     ans = 0;
76     while(ub >= lb) {
77         mid = (ub + lb) >> 1;
78         if(check(mid)) {
79             ans = mid;
80             lb = mid + 1;
81         } else {
82             ub = mid - 1;
83         }
84     }
85     if(ans > 0) {
86         for(int i = 1; i <= ans; i++) {
87             printf("%c", s2[i]);
88         }
89         printf("\n");
90     }
91     else printf("IMPOSSIBLE\n");
92     return 0;
93 }

转载于:https://www.cnblogs.com/Dillonh/p/9502448.html

E.Text Editor (Gym 101466E + 二分 + kmp)相关推荐

  1. html+txt+编辑器,txtPro Text Editor

    txtPro Text Editor是一款文本编辑器,也是一款多语言代码编辑器.html编辑器.多样化的编辑器,你可以选择需要的代码效果,选择你喜欢的字体编辑.txtPro还附带了键盘快捷方式,并正确 ...

  2. Java Code Geeks通过Twitter赠送了免费的Sublime Text Editor许可

    正在与您的重量级编辑斗争? 然后,我们特别为您准备了一些东西! 我们正在举办比赛,免费赠送 kick-ass Sublime Text Editor 许可证 . Sublime Text是用于代码,标 ...

  3. 【Python CheckiO 题解】Text Editor

    CheckiO 是面向初学者和高级程序员的编码游戏,使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务,从而提高你的编码技能,本博客主要记录自己用 Python 在闯关时的做题思 ...

  4. sublime text_Sublime Text Editor赠品报告和获胜者

    sublime text We had Sublime Text Editor Giveaway going on here, now it's ended and we are here to pr ...

  5. HTML Text Editor

    2019独角兽企业重金招聘Python工程师标准>>> HTML Text Editor 实现了基于 WebView 上的 CKEditor 编辑器的功能. 转载:http://ww ...

  6. Dynamics 365 New Feature之Rich Text Editor Control

    在Dynamics 365(CRM)中富文本的编辑一直是刚需,之前都是通过自定义的方式引入富文本功能,现在MS已经引入了该控件. 该控件支持文本,当然因为single text字数有限,一般都会选择m ...

  7. Download EditPlus Text Editor

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

  8. CodeForces - 253C:Text Editor(暴力枚举)

    Discription Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the c ...

  9. Blender:下载并安装文本编辑器(Text Editor)代码自动补全插件

    参考网站: [Addon] Auto Completion in Blenders Text Editor Code Autocomplete Manual#Installation [Youtube ...

最新文章

  1. fckeditor编辑器上传文件出现invalid Request问题解决
  2. 含有min()函数的栈,各种操作时间复杂度为O(1)
  3. 抽象类 VS 接口 (3)
  4. 击败谷歌AI拿下“最强”称号?Facebook AI开源聊天机器人Blender
  5. 人工智能论坛_浙江大学人工智能论坛在北京召开
  6. python怎么画出圆润的曲线_利用python画出AUC曲线的实例
  7. 64位Visual Studio 2022,微软在下一盘大棋!
  8. 拿什么拯救你,我的面试之——从零打卡刷Leetcode(No.003)
  9. 【HDU - 薛猫猫杯程序设计网络赛】【题解】
  10. 应用上云2小时烧掉近50万,创始人:差点破产,简直噩梦
  11. 包含html语言的超链接标记的网页_什么是网页
  12. StarkWare推出ZK Rollup扩容解决方案StarkNet
  13. 浅析HandlerThread
  14. tiny_mce的本地图片上传插件
  15. CPT自定义按钮导出(含参)
  16. 老罗Android开发视频分享
  17. SpringCloud(4)— 统一网关Gateway
  18. 云和恩墨 | 安全稳健 - 全面保障某城商行核心系统大版本顺利升级
  19. 【蓝桥杯单片机】共阳数码管
  20. P4294 [WC2008]游览计划

热门文章

  1. python使用什么注释语句和运算-Python基础之注释,算数运算符,变量,输入和格式化输出...
  2. python是什么语言开发的-少儿编程有什么好处?儿童编程课程学习Python的4大原因...
  3. python小程序源代码-整理了适合新手的20个Python练手小程序
  4. 学习python是干嘛的-学 Python 都用来干嘛的?
  5. python快速入门 pdf-十分钟快速入门python
  6. python的jupyter的使用教程-强大的jupyter,python开发者的福音
  7. python网络爬虫工程师薪资-python网络爬虫工程师找工作应该准备什么?
  8. python游戏编程入门 免费-Python游戏编程入门4
  9. python变量类型-python变量的数据类型有哪些?
  10. python编码规范手册-python之(8)Python编码规范整理