Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy
//因为可以反转n次 所以可以得到任何可以构成的序列
#include<iostream>
#include<string>
#include<vector>
using namespace std ;
typedef pair<int,int>PII;
int n,k;
string s;
string get_str(int n,int k) {//先构建前k-1个
string res="";
for(int i=; i<k-; i++) {
res+="(";
res+=")";
}
int len=n-res.size();
for(int i=; i<len/; i++)
res+="(";//构建最后一个
for(int i=; i<len/; i++)
res+=")";
return res;
}
void solve_swap(int x,int y) {
while(x<y) {
swap(s[x],s[y]);
x++,y--;
}
}
void solve() {
cin>>n>>k;
cin>>s;
vector<PII>res;
string final_str=get_str(n,k);
for(int i=; i<n; i++) {
if(s[i]!=final_str[i]) {
for(int j=i+; j<n; j++) {
if(s[j]==final_str[i]) {
solve_swap(i,j);
res.push_back({i+,j+});
break;
}
}
}
}
cout<<res.size()<<endl;
for(int i=; i<res.size(); i++)
cout<<res[i].first<<" "<<res[i].second<<endl;
}
int main() {
int t;
cin>>t;
while(t--) solve();
return ;
}
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy的更多相关文章
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3
A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最 ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学
F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) E. Arson In Berland Forest 二分 前缀和
E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every ce ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) D2. Optimal Subsequences (Hard Version) 数据结构 贪心
D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造
C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心
B. Box Permutation p is a sequence of integers p=[p1,p2,-,pn], consisting of n distinct (unique) pos ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题
A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B Box
#include<bits/stdc++.h> using namespace std; ]; ]; int main() { int total; cin>>total; w ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A Math Problem
//只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int ...
随机推荐
- IntelliJ IDEA 更新
一. 下载最新版本的idea 1. 官网下载,官网地址:http://www.jetbrains.com/idea/download/#section=windows 2. 百度网盘直接下载:http ...
- 逻辑卷管理(LVM)-快照
1.需要在逻辑卷相同的卷组中创建逻辑卷快照.-s :表示快照 -p r:表示只读 /dev/vg0/mysql 为那个卷的快照 2.查看快照卷信息. 3.快照恢复,必须先取消挂载,还原成功之后,快 ...
- kubernetes安装-二进制
主要参考https://github.com/opsnull/follow-me-install-kubernetes-cluster,采用Flanel和docker 系统信息 角色 系统 CPU C ...
- 将小账本上传到GitHub
在假期的时候我已经注册好了用户 https://www.cnblogs.com/1234yyf/p/12312072.html 然后我将我的小账本上传到GitHub上面:一步一步跟着就可以上传成功!! ...
- P1000题解 超级玛丽游戏
P1000这么难,必须要水一篇题解/斜眼笑 ******** ************ ####....#. #..###.....##.... ###.......###### ### ### .. ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:hbase微博案例
实验目的 熟悉hbase表格设计的方法 熟悉hbase的javaAPI 通过API理解掌握hbase的数据的逻辑视图 了解MVC的服务端设计方式 实验原理 上次我们已经初步设计了学生选课案例的,具体功 ...
- 随机定时修改密码change_passwd.sh
change_passwd.sh #!/bin/sh /usr/bin/chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow /usr/b ...
- 【1】Logistic回归
Logistic回归 在Logistic回归中,损失函数L定义为 成本函数 J 损失函数是单个训练样本的误差,而成本函数是所有训练样本误差的平均值. 之所以选择这个损失函数,是因为该损失函数L与w ...
- springboot的yml配置文件里有多个参数的调用方式
本篇教程适用于配置文件一级下有多个二级或三级时,如何在service层不用通过多个@Value就能获取配置文件的参数 例如yml配置是这样的: 如果service层要引用这些参数,用多个@Value( ...
- EF Code-First(Oracle)通过Migration来更新数据库的表的字段
关于Oracle中使用Entity Framework 6.x Code-First方式开发,请参考博客(菩提树下的杨过)https://www.cnblogs.com/yjmyzz/p/how-to ...