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 ...
随机推荐
- 【DTOJ】2704:数字互换
DTOJ 2704:数字互换 解题报告 2017.11.11 第一版 ——由翱翔的逗比w原创 题目信息: 题目描述 输入两个数作为交换数,输出已交换顺序后的两个值. 输入 两个整数,空格隔开 输出 ...
- PHP-CMS代码审计(4)
这次找了个发卡平台,url: https://files.cnblogs.com/files/b1gstar/kamiphp.zip 从52破解上下载的 : 先把网站搭建起来. 网站没有采用mvc框 ...
- 《茶余饭后小故事》MV*、MVC、MVP、MVVM的前世今生
今天我们讲讲历史,讲讲故事,不扯高深术语. MV*表示的意思是:M(Model逻辑层) + View(视图层) + *(中间者).上帝提出了这个逻辑与视图分离,用中间者进行连接的伟大思想,并将实现这个 ...
- 创建react项目,用typescript语法
create-react-app 文档 typescript 单元测试 官网测试相关文档
- 网络流最大流——dinic算法
前言 网络流问题是一个很深奥的问题,对应也有许多很优秀的算法.但是本文只会讲述dinic算法 最近写了好多网络流的题目,想想看还是写一篇来总结一下网络流和dinic算法以免以后自己忘了... 网络流问 ...
- 深度优先搜索DFS---全球变暖
内心OS:这道题是去年准备HD复试时,我用来练习DFS的.现在再做这道题,感触颇深,唉,时光蹉跎,物是人非啊~~ 题目: 你有一张某海域NxN像素的照片,”.”表示海洋.”#”表示陆地,如下所示: … ...
- js磁力线代码(非压缩,自己在压缩的版本上优化了代码,易于阅读)
拿去白嫖吧: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=" ...
- Wannafly Winter Camp 2020 Day 6A Convolution - NTT
求 \(\sum_{i=1}^n \sum_{j=1}^n 2^{a_ia_j}\) Solution 化简一下 \[ 2^{a_ia_j} = p^{(a_i+a_j)^2-a_i^2-a_j^2} ...
- Cmake编译库注意
在生成工程文件后要在Debug x64模式下菜单栏选择:生成->生成解决方案,等10几分钟然后在Cmake Targets下INSTALL,点击“仅用于项目->仅生成INSTALL”,然后 ...
- 高数(求x的n次方的导数)