当前位置:网站首页>N - string problem HDU - 3374 (max min notation template)
N - string problem HDU - 3374 (max min notation template)
2022-06-21 21:29:00 【fighting_ yifeng】
String Problem HDU - 3374
The question : Give you a string , Let you find the maximum and minimum position of his loop string , And the number of occurrences .
analysis : Good number of occurrences please , You can imagine that if the maximum and minimum appear multiple times, there is a circular string , It is possible to have multiple maxima and minima . Then save the template of the maximum and minimum representation .
#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) // Minimum representation
{
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) // The maximum representation
{
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);
}
}
边栏推荐
- Merge two ordered arrays
- 一行代码可以做什么?
- MySQL数据库---存储引擎
- The first in the industry! Krypton app has obtained the authoritative certification of China Network Security Review Technology and Certification Center
- New hybrid architecture iformer! Flexible migration of convolution and maximum pooling to transformer
- 基于接口划分VLAN:静态VLAN【未完善】
- MySQL learning (from getting started to mastering 1.2)
- 集群一---LVS負載均衡集群NAT模式及LVS負載均衡實戰部署
- [applet] realize applet and background ASP through request Net data JSON transmission (post protocol text + code)
- [CTF] attack and defense world Misc
猜你喜欢

Caricature scientifique | Vous pouvez apprendre l'EEG en regardant les images. Voulez - vous essayer?

晶合集成通过注册:拟募资95亿 合肥建投与美的是股东

PCA based face recognition system and face pose analysis

11、 Beautify the interface
![[CTF] attack and defense world Misc](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[CTF] attack and defense world Misc

The latest simulation test questions and answers of Henan construction electrician (special construction operation) in 2022

Cocoapods installation (after xcode8.0, the infinite card is in the setting up cocoapods master repo)
![[Patents and papers-20]: Operation Guide for electronic information declaration in Nanjing, Jiangsu Province in 2022](/img/bb/313f4a9f9c03ab2e9dfe0e8846831e.png)
[Patents and papers-20]: Operation Guide for electronic information declaration in Nanjing, Jiangsu Province in 2022

Cluster 2 - LVS load balancing cluster Dr mode
![VLAN division based on interface: static VLAN [not perfect]](/img/ba/968b483c3ed96b283aa263dcb0ccdc.png)
VLAN division based on interface: static VLAN [not perfect]
随机推荐
如何解决织梦文章列表自动更新点击次数
JS里的数据类型(基础)
[Patents and papers-19]: Notice on electronic information application of Nanjing City, Jiangsu Province in 2022 (medium and advanced)
Xcode plug-in management tool Alcatraz
用keil 5编译C51时出现定义未使用的处理方法
安全加密简介
Golang learning notes - pointer
ctfshow 105-127
一行代碼可以做什麼?
DEDECMS织梦后台邮箱验证发送邮件配置教程
The latest simulation test questions and answers of Henan construction electrician (special construction operation) in 2022
Several common device communication protocols in embedded development are summarized
LVS+Keepalived高可用群集实战部署
PC e-commerce platform - search module
ACM. HJ35 蛇形矩阵 ●
修改UE4缓存路径,缓解c盘压力
一行代码可以做什么?
Data processing and visualization of machine learning [iris data classification | feature attribute comparison]
Leecode70 climbing stairs
F - Phone List HDU - 1671 (字典树查前缀)