//因为可以反转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. WAF的基础绕过

    方法分类: 1.HTTP参数污染绕过 2.HTTP Header头部欺骗绕过 3.HTTP参数溢出绕过 4.HTTP分块传输绕过 5.HTTP数据编码绕过 6.HTTP Pipline绕过(Keep- ...

  2. sql查询 ——排序

    -- 排序 -- order by 排序 默认为升序 -- asc 升序 -- desc 降序 -- 查询身高 分别用升序和降序 select *from student order by high ...

  3. PHP0014:PHP操作文件

    查看源代码 用这种方式抓取网页,和原始网页一模一样. 数组不能用echo 将一个网页保存到本地html文件

  4. Spring Boot源码(八):Spring AOP源码

    关于spring aop的应用参见:Spring AOP-基于@AspectJ风格 spring在初始化容器时就会生成代理对象: 关于创建bean的源码参见:Spring Boot源码(六):Bean ...

  5. Android开发第一天---AndroidStudio的安装和第一个安卓开发

    今天已经是开始学习Android的第二天,我居然才把AndroidStudio开发环境安装并配置好,我只能说“我太难了”,下了好几个版本,终于找到了一个合适的,得出一个结论外国的东西是真的不太好用啊, ...

  6. PyCharm2019 永久激活(测试通过)

    2019.1.1 专业版 永久期限,需要下载补丁,以及配置文件 补丁地址:https://pan.baidu.com/s/16ALpz_BCXjsRkpS_PtD23A 1,下载安装pycharm程序 ...

  7. 处理异常 ‘try’——‘except’ 方法

    try: name 2+' [][3] {}['k'] ret = int(input('number>>>')) print(ret*'*') except ValueError: ...

  8. (node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out after 30000 ms

    记录一次学习node.js犯的低级错误 这里遇到一个这样的问题 express连接mongoose时报错(node:7584) UnhandledPromiseRejectionWarning: Mo ...

  9. mnist手写数字问题初体验

    上一篇我们提到了回归问题中的梯度下降算法,而且我们知道线性模型只能解决简单的线性回归问题,对于高维图片,线性模型不能完成这样复杂的分类任务.那么是不是线性模型在离散值预测或图像分类问题中就没有用武之地 ...

  10. JAVA中定义不同进制整数

    1.八进制整数以0开头 int b = 033;//表示十进制数27,3 × 81 + 3 × 80 = 3 × 8 + 3 × 1 = 24 + 3 = 27 2.十六进制整数以0x或者0X开头 i ...