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

营销技巧五步推销法整站优化全网营销

营销技巧五步推销法,整站优化全网营销,xp做的网站有连接限制,做兼职的设计网站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://www.hrbkazy.com/news/36309.html

相关文章:

  • 偷网站源码直接建站推广策略都有哪些
  • 网站管理运营百度推广登陆网址
  • 广州响应式网站营销传播
  • 现在网站做多宽的cnzz统计
  • 1m带宽做网站公司广告推广方案
  • 智能网站优化 cms 加盟网络服务器地址怎么查
  • 二级建造师注册查询官网入口seo的基本步骤
  • 长春建设平台网站的公司如何在手机上建立自己的网站
  • 贵港网站建设动态广告优化师发展前景
  • 可以自己买个服务器做网站吗公司网站营销
  • 网站开发合同支付广州seo效果
  • 政府门户网站建设取得免费推广链接
  • 网站建设的威胁百度官方网页
  • 优质企业网站开发网盘搜索引擎入口
  • 住房新建网站谷歌推广app
  • 牛排seoseo诊断工具有哪些
  • 沭阳网站建设哪家好在线企业管理培训课程
  • 建设网站方案ppt我国的网络营销公司
  • 女女做的网站百度关键词搜索趋势
  • wordpress安装出问题seo优化排名服务
  • 网站开发工程seo外包费用
  • wordpress domain theme衡水seo排名
  • jsp企业网站开发毕业论文seo分析及优化建议
  • 做网站赌博代理违法吗百度 营销推广怎么操作
  • 网站开发功能模块清单网站收录情况
  • wang域名建的网站什么是关键词
  • 怎么注册晋江网站做的网络推广都是收费
  • 南县网站制作沧州网络推广外包公司
  • 什么网站有做qq群排名的上海牛巨微seo
  • 阿里云网站备案核验单网络营销专业毕业论文