//因为可以反转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的更多相关文章

  1. 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) 思路:我们想一下如果题目说的是最 ...

  2. 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 ...

  3. 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 ...

  4. 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, ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. python格式化输出保留2位小数

    我是小白就不用多说了,学习python做了个练习题,结果运行了一遍,发现输入金额后得到的有很多位小数, 虽然不知道为什么,但是看得很不舒服, 就想到应该把让小数点后只保留2位数 找到了方法:将{0}改 ...

  2. 图片-定义select向下箭头样式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. Charles抓包工具的破解以及使用

    一.破解 官网下载Charles 下载Charles.jar ,然后按照后在Charles→lib中替换掉Charles.jar 链接:https://pan.baidu.com/s/1XZ-aZI5 ...

  4. vue添加swiper的正确方式亲测---切图网

    在vue项目中,我们在做图片轮播的方式和传统切图不同,传统切图中我们一般采用非常强大的swiper来完成,而在vue中一般依赖vue-awesome-swiper组件来完成(vue-awesome-s ...

  5. #AcWing系列课程Level-2笔记——4. 浮点数二分算法

    浮点数二分算法 编写浮点数二分,记住下面的思路,代码也就游刃有余了! 1.首先找到数组的中间值,mid=(left+right)>>1,区间[left, right]被划分成[left, ...

  6. [Python] 前程无忧招聘网爬取软件工程职位 网络爬虫 https://www.51job.com

    首先进入该网站的https://www.51job.com/robots.txt页面 给出提示: 找不到该页 File not found 您要查看的页已删除,或已改名,或暂时不可用. 请尝试以下操作 ...

  7. GYCTF Flaskapp[SSTI模板注入 ]

    题目复现传送门 学习链接: 找了个师傅的blog先学习一下基础的flask知识 https://www.freebuf.com/column/187845.html(从零学flask) 简单记录一下: ...

  8. MVC开发模式以及Smarty模板引擎的使用

    Linux 全局安装 composer 将目录切换到/usr/local/bin/目录 cd /usr/local/bin/ 在 bin 目录中下载 composer curl -sS https:/ ...

  9. 使用css鼠标移动到图片放大效果

      <!DOCTYPE html>  <html>      <head>          <meta charset="UTF-8"& ...

  10. TamperMonkey 使用指南以及脚本推荐

    写在前面 Chrome浏览器是最适合开发者使用的浏览器,不仅仅是因为Chrome对于Js的友好支持,更是由于Chrome支持丰富且功能强大的插件,扩展了浏览器的功能和使用体验. 在这些插件里面,相信你 ...