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 ...
随机推荐
- XSStrike工具的安装使用
0x01简介 XSStrike 是一款用于探测并利用XSS漏洞的脚本 XSStrike目前所提供的产品特性: 对参数进行模糊测试之后构建合适的payload 使用payload对参数进行穷举匹配 内置 ...
- java new一个对象的过程中发生了什么?
java在new一个对象的时候,会先查看对象所属的类有没有被加载到内存,如果没有的话,就会先通过类的全限定名来加载.加载并初始化类完成后,再进行对象的创建工作. 我们先假设是第一次使用该类,这样的话n ...
- ural 2124
题意 ural 做法 求出一个原根\(\omega\),对于每个数\(x\)写成\(x=\omega^{k}\)的形式,\(\delta(x)=\frac{p-1}{k}\) 我们不关心群具体的东西, ...
- 【感知机模型】手写代码训练 / 使用sklearn的Perceptron模块训练
读取原始数据 import pandas as pd import numpy as np in_data = pd.read_table('./origin-data/perceptron_15.d ...
- C++中用vector定义矩阵
熟悉c风格的矩阵定义,那么用纯c++特性vector如何定义一个矩阵呢? # include<vector> # include <iostream> int main() { ...
- 动手实现一个同步器(AQS)
在多线程情景下,如果不会某一共享变量采取一些同步机制,很可能发生数据不安全现象,比如购买车票时,当多个人购买时,不加锁就会产生多人买同一张票的现象,显然这是不可取的.所以要有一种同步机制,在某一时刻只 ...
- SQL Server误设置max server memory处理小结
昨天网上一网友说,由于他同事误将"max server memory"设置为10M后,SQL Server数据库登录不了,当时我简单测试了一下,今天有空就顺手将整个过程整理一下,记 ...
- Linux环境搭建及基础操作
一.Linux环境搭建 1.安装虚拟机软件(VMWare,Parallel) 虚拟机的作用:将本来不是适合当前操作系统的分区虚拟化成适合当前操作系统的分区格式 2.新建虚拟机: 类似买了一台新的电脑, ...
- 阻止a链接跳转的点击事件
<a href="http://www.baidu.com" id="btn">按钮</a> <script> docume ...
- JavaScript实现动态打字效果
废话不多说,上代码~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...