当前位置:网站首页>ZOJ 1729 & ZOJ 2006(最小表示法模板题)
ZOJ 1729 & ZOJ 2006(最小表示法模板题)
2022-08-09 11:09:00 【AlanLiu6】
输出每个字符串的最小字典序字串的下标!
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 200017;
char str[maxn], tmp[maxn];
//最小表示法
int len;
int get_minstring(char *s)
{
int len = strlen(s);
int i = 0, j = 1, k = 0;
while(i<len && j<len && k<len)
{
int t=s[(i+k)%len]-s[(j+k)%len];
if(t==0)
k++;
else
{
if(t > 0)
i+=k+1;
else
j+=k+1;
if(i==j) j++;
k=0;
}
}
return min(i,j);
}
int main()
{
int t;
int len;
scanf("%d",&t);
while(t--)
{
scanf("%d",&len);
scanf("%s",str);
int ans = get_minstring(str);
printf("%d\n",ans+1);
}
return 0;
}
边栏推荐
- golang 三种指针类型具体类型的指针、unsafe.Pointer、uintptr作用
- 实现strcat函数
- Numpy常用操作博客合集
- Oracle数据库的两种进入方式
- x86 Exception Handling and Interrupt Mechanism (1) Overview of the source and handling of interrupts
- 激光条纹中心提取——灰度重心法
- [C language] creation and use of dynamic arrays
- 论文分享 | ACL2022 | 基于迁移学习的论元关系提取
- FreeRTOS任务创建源码分析
- c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
猜你喜欢
随机推荐
Looper 原理浅析
es6对象迭代器iterator
b站up主:空狐公子 --矩阵求导(分母布局)课程笔记
Netscope: Online visualization tool for neural network structures
fidder为什么不会抓包的问题
PAT1013 并查集 DFS(查找联通分量的个数)
CAN总线发送数据
数论知识点
x86异常处理与中断机制(3)中断处理过程
富媒体在客服IM消息通信中的秒发实践
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
enum in c language
x86异常处理与中断机制(1)概述中断的来源和处理方式
Jmeter BeanShell post processor
Julia资料收集
Qt获取EXE可执行文件的上一级目录下的文件
STM32使用静态队列保存数据
PTA 矩阵运算
golang runtime Caller、Callers、CallersFrames、FuncForPC、Stack作用
enum in c language









