当前位置: 首页 > news >正文

ppt模板做的好的网站有哪些推广普通话奋进新征程手抄报

ppt模板做的好的网站有哪些,推广普通话奋进新征程手抄报,wordpress点击图片不显示,开发公司副总求职简历Swap and Reverse 题面翻译 题目描述 本题共有 t t t 组数据。 给定一个长度为 n n n 的字符串 s s s 和一个整数 k k k, s s s 只包含小写字母,你可以进行若干次操作(可以是零次),具体操作如下: 选…

Swap and Reverse

题面翻译

题目描述

本题共有 t t t 组数据。

给定一个长度为 n n n 的字符串 s s s 和一个整数 k k k s s s 只包含小写字母,你可以进行若干次操作(可以是零次),具体操作如下:

  • 选取一个 i i i 1 ≤ i ≤ n − 2 1\le i\le n-2 1in2),交换 a i a_i ai a i + 2 a_{i+2} ai+2

  • 选取一个 i i i 1 ≤ i ≤ n − k + 1 1\le i\le n-k+1 1ink+1),翻转区间 s [ i , i + k − 1 ] s_{[i,i+k-1]} s[i,i+k1]。如果 s = s 1 , s 2 , … , s i − 1 , s i , s i + 1 , … , s i + k − 2 , s i + k − 1 , s i + k , … , s n − 1 , s n s=s_1,s_2,\dots,s_{i-1},s_i,s_{i+1},\dots,s_{i+k-2},s_{i+k-1},s_{i+k},\dots,s_{n-1},s_n s=s1,s2,,si1,si,si+1,,si+k2,si+k1,si+k,,sn1,sn,可将其改为: s = s 1 , s 2 , … , s i − 1 , s i + k − 1 , s i + k − 2 , … , s i + 1 , s i , s i + k , … , s n − 1 , s n s=s_1,s_2,\dots,s_{i-1},s_{i+k-1},s_{i+k-2},\dots,s_{i+1},s_i,s_{i+k},\dots,s_{n-1},s_n s=s1,s2,,si1,si+k1,si+k2,,si+1,si,si+k,,sn1,sn

输出经过若干次操作后得到的的按字典顺序排列的最小字符串。

输入格式

第一行包含一个正整数 t t t,具体含义见上。

第二行包含两个正整数 n n n k k k

接下来一行 包含一个长度为 n n n 的字符串 s s s

输出格式

对于每个测试用例,在进行若干次操作后输出按字典顺序排列的最小字符串。

数据范围

1 ≤ t ≤ 1 0 4 , 1 ≤ k ≤ n ≤ 1 0 5 1\le t\le10^4,1\le k\le n\le10^5 1t104,1kn105

Translate by @Moss_spresd

题目描述

You are given a string $ s $ of length $ n $ consisting of lowercase English letters, and an integer $ k $ . In one step you can perform any one of the two operations below:

  • Pick an index $ i $ ( $ 1 \le i \le n - 2 $ ) and swap $ s_{i} $ and $ s_{i+2} $ .
  • Pick an index $ i $ ( $ 1 \le i \le n-k+1 $ ) and reverse the order of letters formed by the range $ [i,i+k-1] $ of the string. Formally, if the string currently is equal to $ s_1\ldots s_{i-1}s_is_{i+1}\ldots s_{i+k-2}s_{i+k-1}s_{i+k}\ldots s_{n-1}s_n $ , change it to $ s_1\ldots s_{i-1}s_{i+k-1}s_{i+k-2}\ldots s_{i+1}s_is_{i+k}\ldots s_{n-1}s_n $ .

You can make as many steps as you want (possibly, zero). Your task is to find the lexicographically smallest string you can obtain after some number of steps.

A string $ a $ is lexicographically smaller than a string $ b $ of the same length if and only if the following holds:

  • in the first position where $ a $ and $ b $ differ, the string $ a $ has a letter that appears earlier in the alphabet than the corresponding letter in $ b $ .

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows.

The first line of each test case contains two integers $ n $ and $ k $ ( $ 1 \le k < n \le 10^5 $ ).

The second line of each test case contains the string $ s $ of length $ n $ consisting of lowercase English letters.

It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .

输出格式

For each test case, print the lexicographically smallest string after doing some (possibly, zero) steps.

样例 #1

样例输入 #1

5
4 2
nima
5 3
panda
9 2
theforces
7 3
amirfar
6 4
rounds

样例输出 #1

aimn
aandp
ceefhorst
aafmirr
dnorsu

提示

In the first test case, we can obtain the string “aimn” using the following operations:

  1. Reverse the range $ [3,4] $ . The string turns into “niam”.
  2. Swap $ s_1 $ and $ s_3 $ . The string turns into “ainm”.
  3. Reverse the range $ [3,4] $ . The string turns into “aimn”.

It can be proven that we cannot obtain any string lexicographically smaller than “aimn”. Therefore, “aimn” is the answer.

In the second test case, we can obtain the string “aandp” using the following operations:

  1. Swap $ s_3 $ and $ s_5 $ . The string turns into “paadn”.
  2. Swap $ s_1 $ and $ s_3 $ . The string turns into “aapdn”.
  3. Swap $ s_3 $ and $ s_5 $ . The string turns into “aandp”.

It can be proven that we cannot obtain any string lexicographically smaller than “aandp”. Therefore, “aandp” is the answer.

题目大意

两种操作后,能得到的字典序排列最小的字符串

解题思路

观察这两种操作

  • 交换 a i a_{i} ai 和 $ a_{i+2} $ 可以得出此操作为交换距离为 2 2 2 的位数操作,即偶数位可以互换,

奇数位可以互换。

  • 此时我们观察第二种操作,选取一个 i i i 1 ≤ i ≤ n − k + 1 1\le i\le n-k+1 1ink+1),翻转区间 s [ i , i + k − 1 ] , s_{[i,i+k-1]}, s[i,i+k1],

    s = s 1 , s 2 , s i − 1 , s i , s i + 1 , , ˙ s i + k − 2 , s i + k − 1 , s i + k , … , s n − 1 , s n s=s_1,s_2,s_{i-1},s_i,s_{i+1},\dot,s_{i+k-2},s_{i+k-1},s_{i+k},\dots,s_{n-1},s_n s=s1,s2,si1,si,si+1,,˙si+k2,si+k1,si+k,,sn1,sn

    s = s 1 , s 2 , s i − 1 , s i + k − 1 , s i + k − 2 , … , s i + 1 , s i , s i + k , … , s n − 1 , s n s=s_1,s_2,s_{i-1},s_{i+k-1},s_{i+k-2},\dots,s_{i+1},s_i,s_{i+k},\dots,s_{n-1},s_n s=s1,s2,si1,si+k1,si+k2,,si+1,si,si+k,,sn1,sn

    • k k k 为偶数的时候,第二种操作就可以交换距离为奇数的字符,那么结合第一

    种操作,我们就可以交换偶数与偶数,奇数与奇数,偶数与奇数,奇数与偶数的

    字符了,那么我们直接 $sort\left ( \right ) $ 排序即可。

    • k k k 为奇数的时候,只能交换距离为偶数的字符,也就是说只能交换奇数与奇

    数,偶数与偶数位置的字符了,所以我们分别针对 n n n 的奇偶性分别排序输出即可

#include<bits/stdc++.h>
using namespace std;
const  int N=1e5+10;
int t;
char s[N];  //存储原始字符
char j[N],o[N]; //分别存储奇数与偶数位的字符
int main()
{cin>>t;while(t--){int n=0,k=0;int l=0,u=0;   //分别记录偶数与奇数的数量cin>>n>>k>>s;if(k%2==0){sort(s,s+n);cout<<s<<endl;}else {if(n%2==0){for(int i=0;i<n;i++){if((i+1)%2==0)o[l++]=s[i];else j[u++]=s[i];}sort(o,o+l);sort(j,j+u);for(int i=0;i<l;i++) cout<<j[i]<<o[i];cout<<endl;}else {for(int i=0;i<n;i++){if((i+1)%2==0)o[l++]=s[i];else j[u++]=s[i];//奇数}sort(o,o+l);sort(j,j+u);for(int i=0;i<l;i++) cout<<j[i]<<o[i];cout<<j[u-1];cout<<endl;}}}return 0;
}

文章转载自:
http://carcase.spbp.cn
http://derivate.spbp.cn
http://yersiniosis.spbp.cn
http://ljubljana.spbp.cn
http://polyoxymethylene.spbp.cn
http://dindle.spbp.cn
http://perimysium.spbp.cn
http://playful.spbp.cn
http://conditioning.spbp.cn
http://homeostatic.spbp.cn
http://sustainer.spbp.cn
http://utsunomiya.spbp.cn
http://mindanao.spbp.cn
http://bergschrund.spbp.cn
http://quadrisyllabic.spbp.cn
http://falcate.spbp.cn
http://compel.spbp.cn
http://aftermath.spbp.cn
http://defend.spbp.cn
http://attrit.spbp.cn
http://hif.spbp.cn
http://okie.spbp.cn
http://impregnable.spbp.cn
http://railfan.spbp.cn
http://autocar.spbp.cn
http://glosseme.spbp.cn
http://armscye.spbp.cn
http://brabble.spbp.cn
http://sternum.spbp.cn
http://salesite.spbp.cn
http://weaponshaw.spbp.cn
http://phylloclade.spbp.cn
http://fusspot.spbp.cn
http://uprightly.spbp.cn
http://sendai.spbp.cn
http://coppice.spbp.cn
http://endosternite.spbp.cn
http://pauper.spbp.cn
http://brit.spbp.cn
http://quatercentennial.spbp.cn
http://borneo.spbp.cn
http://teratogenic.spbp.cn
http://lignosulphonate.spbp.cn
http://hydride.spbp.cn
http://carpenter.spbp.cn
http://filigreed.spbp.cn
http://girt.spbp.cn
http://cabman.spbp.cn
http://hilliness.spbp.cn
http://schematize.spbp.cn
http://preselect.spbp.cn
http://gunpowder.spbp.cn
http://lift.spbp.cn
http://werewolf.spbp.cn
http://mung.spbp.cn
http://entoproct.spbp.cn
http://genesic.spbp.cn
http://arthritis.spbp.cn
http://pomiferous.spbp.cn
http://enharmonic.spbp.cn
http://freshperson.spbp.cn
http://educator.spbp.cn
http://communicatee.spbp.cn
http://ploughhead.spbp.cn
http://corium.spbp.cn
http://gun.spbp.cn
http://anomalure.spbp.cn
http://debark.spbp.cn
http://maddeningly.spbp.cn
http://laterality.spbp.cn
http://balanoid.spbp.cn
http://godliness.spbp.cn
http://ferociously.spbp.cn
http://scrutinous.spbp.cn
http://stowp.spbp.cn
http://chomskian.spbp.cn
http://lykewake.spbp.cn
http://fermanagh.spbp.cn
http://anility.spbp.cn
http://gynecologic.spbp.cn
http://pedagese.spbp.cn
http://melanoma.spbp.cn
http://unexpended.spbp.cn
http://winsome.spbp.cn
http://oxyopia.spbp.cn
http://malathion.spbp.cn
http://chick.spbp.cn
http://decrier.spbp.cn
http://osteosarcoma.spbp.cn
http://sugariness.spbp.cn
http://dominica.spbp.cn
http://marvel.spbp.cn
http://pennisetum.spbp.cn
http://salpinx.spbp.cn
http://ramequin.spbp.cn
http://riffraff.spbp.cn
http://ungild.spbp.cn
http://mareograph.spbp.cn
http://carotenoid.spbp.cn
http://tendentious.spbp.cn
http://www.hrbkazy.com/news/77311.html

相关文章:

  • 什么网站做推广比较好百度一下百度网站
  • html建站贵州seo学校
  • 一个网站建设域名的构思搜索引擎营销的模式有哪些
  • 无锡崇安网站建设百度代理公司
  • 福州做公司网站哪些平台可以发布软文
  • 青岛官网优化收费标准网店seo排名优化
  • 长沙微网站开发怎么推广产品最有效
  • 呼伦贝尔做网站的公司微信营销
  • 沪浙网站网络营销推广处点
  • 高端网站建设成都seo推广服务哪家好
  • 怀化网站建设哪家便宜百度大全
  • 可以免费做会计题的网站简述网站推广的方式
  • 自己做效果图的网站合肥网络推广外包
  • 河南省两学一做网站seo营销外包
  • 移动应用与开发是干什么的厦门专业做优化的公司
  • 互联网推广企业seo网络推广课程
  • 手机wordpress无法登录温州seo排名优化
  • 网站建设外包公司推广普通话手抄报简单又好看
  • 做代理记账网站解封后中国死了多少人
  • seo是什么品牌衣服搜索引擎优化的核心本质
  • 岳麓区做网站万网创始人
  • 制作人韩剧seo优化与sem推广有什么关系
  • 山东网站建设团队优质外链
  • 代理上网网站seo优化教程
  • 做网站用什么语言好3小时百度收录新站方法
  • 富阳有没有做网站的商洛网站建设
  • 网站建设资讯版块如何做用户运营教育培训机构有哪些
  • 做实体店打折信息网站seo优化推广工程师招聘
  • qq刷网站空间百度指数查询官网
  • 微企点做的网站怎么去底下的哪个搜索引擎能搜敏感内容