当前位置:网站首页>N - String Problem HDU - 3374(最大最小表示法模板)
N - String Problem HDU - 3374(最大最小表示法模板)
2022-06-21 19:39:00 【fighting_yifeng】
String Problem HDU - 3374
题意:给你一个字符串,让你求他的循环串的最大最小的位置,以及出现次数。
分析:出现次数很好求了,你可想如果最大最小出现多次即存在循环串,才有可能有多个最大最小。然后就是最大最小表示法的模板存一下。
#include <iostream>
#include <cstdio>
#include <stack>
#include <cmath>
#include <set>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 1000010;
int next1[maxn], n, m, t;
char x[maxn], y[maxn];
void kmp_pre(int m)
{
int i, j;
j = -1;next1[0] = -1;
i = 0;
while(i < m){
while(-1 != j && x[i] != x[j]) j = next1[j];
next1[++i] = ++j;
}
}
int minmum(int len) // 最小表示法
{
int i = 0, j = 1, k = 0;
while(i < len && j < len && k < len){
int temp = x[(i + k) % len] - x[(j + k) %len];
if(temp == 0) k++;
else{
if(temp > 0) i = i + k + 1;
else j = j + k + 1;
if(i == j) j++;
k = 0;
}
}
return i < j ? i : j;
}
int maxmum(int len) // 最大表示法
{
int i = 0, j = 1, k = 0;
while(i < len && j < len && k < len){
int temp = x[(i + k) % len] - x[(j + k) %len];
if(temp == 0) k++;
else{
if(temp > 0) j = j + k + 1;
else i = i + k + 1;
if(i == j) j++;
k = 0;
}
}
return i < j ? i : j;
}
int main()
{
while(~scanf("%s", x))
{
m = strlen(x);
kmp_pre(m);
int num = 1, len = m - next1[m];
if(m % len == 0)
num = m / len;
int minn = minmum(m);
int maxx = maxmum(m);
printf("%d %d %d %d\n", minn + 1, num, maxx + 1, num);
}
}
边栏推荐
- 网关是什么
- 数据路:三人行,必有我师!
- MySQL数据库---存储引擎
- What are the applications of 4.3-inch touch screen intelligent network central control host
- Kubernetes-23:详解如何将CPU Manager做到游刃有余
- How functions are declared
- The final scheme of adding traceid at the C end
- About n before variables in SQL server and other usage analysis
- 2022年全国最新消防设施操作员(中级消防设施操作员)模拟题库及答案
- 腾讯全球数字生态大会-高速智能计算专场!
猜你喜欢

Take off, annual salary: 400000+

Most detailed collation of vector basis of STL

集群二---LVS负载均衡群集DR模式

Shutter input box assembly

PowerPoint 教程,如何在 PowerPoint 中将幻灯片整理成组?

SMILES的基本规则

基于 PCA 的人脸识别系统及人脸姿态分析

Check information on the Internet after the college entrance examination, and pay attention to prevent websites without SSL certificates
![[applet] realize applet and background ASP through request Net data JSON transmission (post protocol text + code)](/img/e7/1a270d2aa03f38426bc57bd0ee00b6.png)
[applet] realize applet and background ASP through request Net data JSON transmission (post protocol text + code)

异步方法 理解(demo附代码)
随机推荐
[专利与论文-20]:江苏省南京市2022年电子信息申报操作指南
Vertical and horizontal network shooting range community Modbus Protocol
ADUM1401ARWZ-RL 亚德诺 数字信号隔离模块
Welcome to the markdown editor
期货开户平台哪家好?安全正规的期货公司有哪些?
Most detailed collation of vector basis of STL
Shutter input box assembly
向量与平面交点
Extend the clean, fresh and dense bag, and put a "safety lock" on the ingredients
NS32F103VBT6软硬件替代STM32F103VBT6
全新混合架构iFormer!将卷积和最大池化灵活移植到Transformer
Shutter tabbarview component
網關是什麼
PCA based face recognition system and face pose analysis
Cluster I - LVS Load Balancing Cluster Nat Mode and LVS Load Balancing Field Deployment
Adum1401arwz-rl adenault digital signal isolation module
MediaCodec的数据类型和使用方式
【微服务七】Ribbon负载均衡策略之BestAvailableRule源码深度剖析
Introduction to high performance intranet DNS system
【owt】p2p Signaling Server 运行