CF126B Password
思路:
kmp略作修改。
实现:
- #include <iostream>
- #include <cstdio>
- using namespace std;
- const int MAXN = ;
- int neXt[MAXN];
- void getNext(string s)
- {
- int n = s.length();
- neXt[] = -;
- int k = -, j = ;
- while (j < n)
- {
- if (k == - || s[j] == s[k])
- {
- j++; k++;
- neXt[j] = k;
- }
- else
- {
- k = neXt[k];
- }
- }
- }
- bool kmp(string s, string p)
- {
- int i = , j = ;
- int m = s.length(), n = p.length();
- while (i < m && j < n)
- {
- if (j == - || s[i] == p[j]) i++, j++;
- else j = neXt[j];
- }
- if (j == n) return true;
- return false;
- }
- int main()
- {
- string str;
- cin >> str;
- str += ' ';
- int n = str.length();
- getNext(str);
- int tmp = neXt[n - ];
- bool flg = false;
- while (tmp)
- {
- if (kmp(str.substr(, n - ), str.substr(, tmp)))
- {
- cout << str.substr(, tmp) << endl;
- flg = true;
- break;
- }
- tmp = neXt[tmp];
- }
- if (!flg) cout << "Just a legend" << endl;
- return ;
- }
CF126B Password的更多相关文章
- KMP CF126B Password
Description Asterix,Obelix和他们的临时伙伴Suffix.Prefix已经最终找到了和谐寺.然而和谐寺大门紧闭,就连Obelix的运气也没好到能打开它. 不久他们发现了一个字符 ...
- CF126B password&&HDU 4763 Theme Section
http://acm.hdu.edu.cn/showproblem.php?pid=4763 http://codeforces.com/problemset/problem/126/B 这两个题都是 ...
- CF126B Password【KMP】By cellur925
题目传送门 其实$Chemist$在之前写了非常棒的题解! 我长话短说,补充两句. “那么当$next[n]$>$max$时显然不能将$next[n]$作为最长子串的长度”这句话其实在说,因为一 ...
- CF126B
CF126B Password 题意: 给出一个字符串 H,找一个最长的字符串 h,使得它既作为前缀出现过.又作为后缀出现过.还作为中间的子串出现过. 解法: 沿着 $ next_n $ 枚举字符串, ...
- 浅谈KMP算法——Chemist
很久以前就学过KMP,不过一直没有深入理解只是背代码,今天总结一下KMP算法来加深印象. 一.KMP算法介绍 KMP解决的问题:给你两个字符串A和B(|A|=n,|B|=m,n>m),询问一个字 ...
- 2021.08.30 前缀函数和KMP
2021.08.30 前缀函数和KMP KMP算法详解-彻底清楚了(转载+部分原创) - sofu6 - 博客园 (cnblogs.com) KMP算法next数组的一种理解思路 - 挠到头秃 - 博 ...
- 「CF126B」Password
题目描述 给定一个字符串 \(S\),我们规定一个字符串 \(P\) 是可行解,\(P\) 需要满足: \(P\) 是 \(S\) 的前缀 \(P\) 是 \(S\) 的后缀 \(P\) 出现在 \( ...
- 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?
p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...
- your password has expired.to log in you must change it
今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...
随机推荐
- RabbitMQ-rabbitMq各个特性的使用(三)
准备 1.引入客户端和配置文件依赖类 <dependency> <groupId>com.rabbitmq</groupId> <artifactId> ...
- 最小生成树 B - Networking
You are assigned to design network connections between certain points in a wide area. You are given ...
- 四则运算结对编程(GUI)
四则运算GUI coding地址:https://git.dev.tencent.com/qyj814/GUI.git 结对伙伴:李梦宇 一.题目要求 定制出题要求.每次出题时用户都可以在界面上定制如 ...
- Ubuntu 16.04下没有“用户和组”功能的问题解决
在16.04以前的版本会自带“用户和组”的功能,但是在16.04发现系统只自带了“用户账户”的功能. 问题解决: 1.安装gnome-system-tools sudo apt-get install ...
- react实现ssr服务器端渲染总结和案例(实例)
1.什么是 SSR SSR 是 server side render 的缩写,从字面上就可以理解 在服务器端渲染,那渲染什么呢,很显然渲染现在框架中的前后端分离所创建的虚拟 DOM 2.为什么要实现服 ...
- Spring注解配置定时任务<task:annotation-driven/>
http://m.blog.csdn.net/article/details?id=50945311 首先在配置文件头部的必须要有: xmlns:task="http://www.sprin ...
- 字符串的切割操作(strtok,split)
一:strtok C/C++:char *strtok(char s[], const char *delim); s 代表须要切割的字符串,delim代表切割的标志,參数都为比选!返回指向切割部分的 ...
- ROBODK仿真如何设置运动速度
设置工具-选项-运动,把仿真时间设置成跟正常一样 然后双击机器人,设置参数(可以设置movej和movel的速度,加速度)
- HttpClient的Post和Get訪问网页
一.基础JAR包 Mavenproject下pom.xml需配置的jar包 <dependencies> <dependency> <groupId>junit&l ...
- 配置hadoop集群一
花了1天时间最终把环境搭建好了.整理了一下,希望对想学习hadoop的有所帮助. 资料下载:http://pan.baidu.com/s/1kTupgkn 包括了linux虚拟机.jdk, hadoo ...