Codeforce Div2 ——B. String Modification

手把手教你在Keil/IAR中移植SEGGER_RTT组件(避坑指南+性能对比) 本文详细介绍了在Keil/IAR开发环境中移植SEGGER RTT调试组件的完整流程与优化技巧。通过对比传统串口调试,SEGGER RTT凭借零硬件占用、高速传输和双向交互等优势,显著提升嵌入式开发效率。文章包含配置步骤、性能调优方案及常见问题解决方案,是嵌入式开发者必备的实用指南。 阅读详情

Vasya has a string ss of length nn. He decides to make the following modification to the string:

Pick an integer kk, (1≤k≤n1≤k≤n).
For ii from 11 to n−k+1n−k+1, reverse the substring s[i:i+k−1]s[i:i+k−1] of ss. For example, if string ss is qwer and k=2k=2, below is the series of transformations the string goes through:

○ qwer (original string)
○ wqer (after reversing the first substring of length 22)
○ weqr (after reversing the second substring of length 22)
○ werq (after reversing the last substring of length 22)

Hence, the resulting string after modifying ss with k=2k=2 is werq.

Vasya wants to choose a kk such that the string obtained after the above-mentioned modification is lexicographically smallest possible among all choices of kk. Among all such kk, he wants to choose the smallest one. Since he is busy attending Felicity 2020, he asks for your help
A string aa is lexicographically smaller than a string bb if and only if one of the following holds
aa is a prefix of bb, but a≠ba≠b;
in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

Input
Each test contains multiple test cases
The first line contains the number of test cases tt (1≤t≤50001≤t≤5000). The description of the test cases follows
The first line of each test case contains a single integer nn (1≤n≤50001≤n≤5000) — the length of the string ss
The second line of each test case contains the string ss of nn lowercase latin letters
It is guaranteed that the sum of nn over all test cases does not exceed 50005000.

output
For each testcase output two lines
In the first line output the lexicographically smallest string s′s′ achievable after the above-mentioned modification
In the second line output the appropriate value of kk (1≤k≤n1≤k≤n) that you chose for performing the modification. If there are multiple values of kk that give the lexicographically smallest string, output the smallest value of kk among them.

example input

6
4
abab
6
qwerty
5
aaaaa
6
alaska
9
lfpbavjsm
1
p

example output

abab
1
ertyqw
3
aaaaa
1
aksala
6
avjsmbpfl
5
p
1

Note
In the first testcase of the first sample, the string modification results for the sample abab are as follows
for k=1k=1 : abab
for k=2k=2 : baba
for k=3k=3 : abab
for k=4k=4 : baba
The lexicographically smallest string achievable through modification is abab for k=1k=1 and 33. Smallest value of kk needed to achieve is hence 11.

经过研究样例可以发现规律,每组的输出都是截取前面字符串的一部分进行翻转后放到另一部分字符串的后面,并且当另一部分字符串字符个数是偶数时截取的那一部分进行翻转,奇数时不翻转,这样,我们枚举所有的情况进行比较,会得到最合适的答案

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
// *start on @date: 2020-02-29 14:21 
using namespace std;
int main()
{
    int m;
    cin>>m;
    while(m--)
    {
        int n;
        int flag=1;
        string s ;
        cin >> n;
        cin >> s;
        string k ="zzzzzz";
        for(int i=0; i<n; i++)
        {
            string a = s.substr(i);
            string b = s.substr(0,i);
            if((n-i)%2)
            {
                reverse(b.begin(),b.end());
                a+=b;
            }
            else a+=b;
            if(k>a)
            {
                flag=i+1;
                k = a;
            }
        }
        cout<<k<<endl<<flag<<endl;
    }      
return 0;
}
深度学习12—VGG19实现 state_dict = load_state_dict_from_url(model_urls['vgg19'],model_dir='./model' ,progress=progress)#预训练模型地址。accuracy=((out.argmax(1)==label).sum()).clone().detach().cpu().numpy()#正确预测的总和比测试集的长度,即预测正确的精度。image=torch.reshape(image,(1,3,224,224))#四维图形,RGB三个通。 阅读详情

相关推荐

5G核心技术:N3与N4接口深度解析

5G网络中,N3和N4接口是实现用户数据传输的核心。N3接口是gNB与UPF之间的用户面通道,采用GTP-U协议封装数据,通过UDP/IP传输,确保低时延和业务隔离。N4接口是SMF与UPF之间的控制面链路,基于PFCP协议下发转发规则(FAR/TDR/QER/URR),实现精细化流量控制。二者协同工作:N4下发策略(如QoS、计费规则),N3执行数据转发,共同支持5G三大场景(eMBB/uRLLC/mMTC),体现控制与转发分离(CUPS)架构优势。

Qinti_mm的博客 1637

Codeforces 201(DIV2)B

B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation of length n is an integer sequence such

PsTree 450

飞书云文档API实战:从权限申请到自动化操作

本文详细介绍了飞书云文档API的实战应用,从权限申请到自动化操作。内容涵盖如何创建应用、获取关键API权限、理解并使用Tenant Access Token,并通过Python代码示例演示了读取和写入飞书表格数据的具体方法,旨在帮助开发者和业务人员实现文档数据处理的自动化,提升工作效率。

weixin_28318011的博客 1943

B. String Modification

手写一下样例不难发现,交换k次就是把原字符串的前缀后缀重新拼接,注意交换次数为奇数的时候还需要翻转前缀。

jisuanji2606414的博客 209

纽马克-贝塔法(Newmark-Beta Method)在结构动力学中的应用与实现

本文深入解析了纽马克-贝塔法(Newmark-Beta Method)在结构动力学数值计算中的核心原理与应用。作为经典的时间积分算法,它通过调节γ和β参数,在计算精度、稳定性与效率间取得平衡,尤其适用于地震响应、风振分析等工程场景。文章详细阐述了其数学内核、在有限元分析中的实现步骤,并对比了隐式与显式方案的适用场景,为工程师提供了关键的方法选择与参数调优指导。

weixin_29232121的博客 148

【Seurat绘图进阶】从参数调优到美学定制:解锁DimPlot与FeaturePlot的隐藏技巧

本文深入探讨了Seurat包中DimPlot与FeaturePlot的进阶使用技巧,旨在解决单细胞数据可视化中的常见痛点。通过参数调优(如order、shuffle、raster)、颜色美学定制(使用RColorBrewer、viridis配色)以及性能优化(栅格化处理),并结合scCustomize包与patchwork排版,帮助用户将基础图表提升为信息清晰、可直接用于论文发表的出版级可视化结果。

lake5的博客 630

CodeCraft-20 B. String Modification

Vasya has a stringssof lengthnn. He decides to make the following modification to the string: Pick an integerkk, (1≤k≤n1≤k≤n). Foriifrom11ton−k+1n−k+1, reverse the substrings[i:i+k−1]s[i:i...

★探梦少年☆的博客 308

知识图谱_知识图谱 | 知识图谱做用户画像

导读:最近一直在思考怎么用知识图谱做推荐,但是目前能知道的内容都是基于路径的推荐和基于图特征的推荐,所以能不能换一个角度,探究一下用知识图谱怎么做用户画像,因为画像也是推荐系统重要的一部分。现在的知识图谱+推荐怎么做的传统的用户画像怎么做现在的知识图谱+推荐怎么做的?基于路径:可以理解成基于图谱的多路径召回,或者多路径推荐,然后根据路径的转移概率进行排序从而达到推荐的效果,基于路径比较适合简单的推...

weixin_28801659的博客 1461

Codeforce-CodeCraft-20 (Div. 2)-B. String Modification (找规律+模拟)

Vasya has a string s of length n. He decides to make the following modification to the string: Pick an integer k, (1≤k≤n). For i from 1 to n−k+1, reverse the substring s[i:i+k−1] of s. For example, if...

日拱一卒,功不唐捐 2881

车载测试实战:adb logcat日志高效抓取与问题定位技巧

本文详细介绍了车载测试中adb logcat日志的高效抓取与问题定位技巧。作为车载测试的“第一现场”,adb logcat能实时、精准地抓取系统与应用日志,是定位应用崩溃、ANR及功能异常等问题的关键工具。文章从环境搭建、核心命令组合拳到实战分析与自动化脚本,提供了完整的操作指南,帮助测试人员快速掌握这一必备技能,大幅提升问题排查效率。

ii567的博客 1041

短信验证码逻辑漏洞学习——各种绕过姿势技巧

短信验证码逻辑漏洞学习——各种绕过姿势技巧

记录并分享学习安全的知识点.. 2557

String Modification CodeForces - 1316B (找规律)

题目链接 Vasya has a string s of length n. He decides to make the following modification to the string: Pick an integer k, (1≤k≤n). For i from 1 to n−k+1, reverse the substring s[i:i+k−1] of s. For examp...

xqx_Zi_yu 393

自动识别象棋棋子的OpenCV应用

在计算机视觉领域,OpenCV是一个广泛应用的开源计算机视觉库,它提供了丰富的图像处理和分析工具。本文将介绍如何使用OpenCV实现自动识别象棋棋子的功能,并提供相应的源代码。通过以上代码,我们可以实现对棋盘图像中棋子的自动识别。需要注意的是,以上代码只是一个简单的示例,实际应用中可能需要根据具体情况进行参数调整和算法优化,以获得更好的识别效果。函数利用预处理后的图像,寻找图像中的轮廓,并根据轮廓的面积筛选出可能的棋子轮廓,最后在原图像中提取棋子区域。在主程序中,我们读取输入图像,并调用。

WzisTypescript的博客 908

CodeCraft-20 (Div. 2)B.String Modification

B. String Modification time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vasya has a string s of length n. He decides to make the following modif...

菜鸡的学习记录 658

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

String Modification

Vasya has a string s of length n. He decides to make the following modification to the string: Pick an integer k, (1≤k≤n). For i from 1 to n−k+1, reverse the substring s[i:i+k−1] of s. For example, if...

sky123博客 605

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

String Modification CodeForces - 1316B(规律)

Vasya has a string s of length n. He decides to make the following modification to the string: Pick an integer k, (1≤k≤n). For i from 1 to n−k+1, reverse the substring s[i:i+k−1] of s. For example, if...

starlet_kiss的博客 476

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

String Modification (CodeCraft-20 (Div. 2))

题意描述 Vasya has a string s of length n. He decides to make the following modification to the string: Pick an integer k, (1≤k≤n). For i from 1 to n−k+1, reverse the substring s[i:i+k−1] of s. For exampl...

Dejavu的博客 1925

CodeCraft-20 (Div. 2) 题解

A. Grade Allocation 查看题解 水题

忘梦心的博客 854

codeforces B. String Modification

B. String Modification time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vasya has a string s of length n. He decides to make the following modif...

忘梦心的博客 669

CodeCraft-20 (Div. 2) B. String Modification(字符串)

传送门 题意: 给一个字符串,按照规则翻转,找到由原字符串翻转出来字典序最小的字符串 思路: 要想最小,字符串中最小的字符应该在第一位,遍历字符串找到所有字符最小的位置,然后进行翻转看哪个最小即可 翻转规律: s1,s2,s3,s4,s5 如果k=4,一共需要翻转2次 发现翻转后的字符串是s4,s5,s1,s2,s3 发现字符串分为前面一部分和后面一部分,后面的一部分不变,放到最前面;前面那一部分...

_Alexander的博客 480

# CodeCraft-20 (Div. 2)

CodeCraft-20 (Div. 2) A. Grade Allocation 思路 : 无脑水题 代码 #include<iostream> #include<algorithm> #include<vector> using namespace std; const int Len = 1e3 + 5; int ar[Len]; int ma...

做一只熊猫不好吗? 315

Codeforces #545 div2 B

题意 给你两行字符串,长度均为n,由01构成,现在让你从中选择n/2个位置,使得选择 的位置上的第一个字符串上的1的个数等于剩下位置上的第二个字符串上的1的个数 思路 一共四种类型,00,10,01,1100,10,01,1100,10,01,11,设其总数分别为,v[0],v[1],v[2],v[3]v[0],v[1],v[2],v[3]v[0],v[1],v[2],v[3] 又设在第一个字符串...

萌新也要搞算法 268

Codeforces Round #562 (Div. 2) B. Pairs(思维)

B. Pairs 【题意】 给出 n (所有出现的数字范围在1...n),有 m 组数对,每组为(a, b) 问是否存在x,y 使得对于每组数至少有一个是 x 或 y 【分析】 因为看了下tags,写着 graphs,所以我就往图上想了想... 然后想用领接表来着,但是...很显然会超时嘛 但是还没 T 就先 wa 了,可能哪里没处理好吧 THEN.... 这是道思维题~ 首...

来啦(#^.^#) 470

[codeforces 1316B] String Modification 力挽狂澜

CodeCraft-20 (Div. 2) 比赛人数7369 [codeforces 1316B] String Modification 力挽狂澜 总目录详见https://blog.csdn.net/mrcrack/article/details/103564004 在线测评地址https://codeforces.ml/contest/1316/problem/B Probl...

mrcrack的博客 514

Vasya and String(答案错误 超时了)

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<iomanip> using namespace std; int main() { char c[100000]; int n, k; cin >> n &...

weixin_45988242的博客 149

Codeforces Round #539 (Div. 2) B. Sasha and Magnetic Machines(思维)

  题目链接:https://codeforces.com/contest/1113/problem/B        题意是给了n个数,可以令一个数乘以x倍,再令另一个数缩小x倍,问操作最多一次后的总和最小是多少。        思路就是暴力,我们对于每一个数的每一个因子都操作一遍,更新一个最小值就好了。 AC代码: #include &lt;bits/stdc++.h&gt; us...

Charles_Zaqdt的博客 775
上一篇: auto (C++11) 自动类型推导:auto关键字
下一篇: Codeforces Div2——C. Primitive Primes
NGUP_LEE
博客等级 码龄7年 277粉丝 171原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值