思路:

构造题。首先把字符串变成“(((((...)))))”的样子,再根据k的取值变成“()()()...((...))”的样子即可。

实现:

 #include <bits/stdc++.h>
using namespace std;
int main()
{
int T; cin >> T;
while (T--)
{
int n, k; string s; cin >> n >> k >> s;
vector<pair<int, int>> res;
for (int i = ; i < n / ; i++)
{
if (s[i] == '(') continue;
int j = i + ;
while (j < n && s[j] != '(') j++;
res.push_back(make_pair(i, j));
reverse(s.begin() + i, s.begin() + j + );
}
for (int i = ; i < k - ; i++)
{
int cur = * i + ;
int j = cur + ;
while (j < n && s[j] != ')') j++;
res.push_back(make_pair(cur, j));
reverse(s.begin() + cur, s.begin() + j + );
}
cout << res.size() << endl;
for (auto it: res)
{
cout << it.first + << " " << it.second + << endl;
}
}
return ;
}

CF1227C Messy的更多相关文章

  1. IOI2016Day2. Messy

    题目链接:http://uoj.ac/problem/239 题目大意: 这是一道交互题,交互库维护了一个数据结构,可以存储n为二进制串,一开始你可以向空的数据结构中插入若干二进制串, 接下来这个数据 ...

  2. Messy Code in Windows Server 2008 R2 English Edition

          We always use Windows Server 2008 R2 English operation system. And it doesn't have any problem ...

  3. the solution about &quot;messy code&quot; in elicpse

    I use the Elicpse IDE to develope the ansdroid app.Sometime encounter the messy code in the Elicpse ...

  4. Chinese Messy Code of String

    It's very strange that I found the messy code.I 've never seen this before. this is the java code: / ...

  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. .net 中文显示乱码问题(Chinese display with messy code)

    Case:同样的代码,本地开发环境(local is Chinese Simplify)可以成功运行,但是放到Windows Server 2008 R2(Local is United State) ...

  7. BNU OJ 50998 BQG's Messy Code

    #include <cstdio> #define _(l) int l #define ___(l,L) for (_(o)=0,x=l o*2;o<x;o++)O= L o; # ...

  8. IS Kali: installed chiess messy code problem

    apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy init 6

  9. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy

    //因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> us ...

随机推荐

  1. HashMap与HashTable的理解与区别

    Hashtable是java一开始发布时就提供的键值映射的数据结构,而HashMap产生于JDK1.2.虽然Hashtable比HashMap出现的早一些,但是现在Hashtable基本上已经被弃用了 ...

  2. Python爬虫:requests 库详解,cookie操作与实战

    原文 第三方库 requests是基于urllib编写的.比urllib库强大,非常适合爬虫的编写. 安装: pip install requests 简单的爬百度首页的例子: response.te ...

  3. 第一章 初识Linux shell

    Linux 由内核.GNU.桌面环境.应用软件四部分组成 内核基本功能: (1). 管理内存 (2). 管理硬件设备 (3). 管理文件系统 (4). 管理软件程序 GNU:操作系统需要一些工具来执行 ...

  4. List集合类

    1.1:  List.add方法——向集合列表中添加对象 public static void main(String[] args) { List<String> list=new Ar ...

  5. Best free and public DNS servers of 2019

    1. OpenDNSPrimary, secondary DNS servers: 208.67.222.222 and 208.67.220.220 2. CloudflarePrimary, se ...

  6. stdu1309(不老的传说)

    题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1309.html 不老的传说问题 Ti ...

  7. 数据结构Java版之排序算法(二)

    排序按时间复杂度和空间复杂度可分为 低级排序 和 高级排序 算法两种.下面将对排序算法进行讲解,以及样例的展示. 低级排序:冒泡排序.选择排序.插入排序. 冒泡排序: 核心思想,小的数往前移.假设最小 ...

  8. 关于 Win10 下使用 IETester 的问题

    真没想到,现在都用上Win10了,居然还会有使用 IETester 的需求,今天一个客户反应界面出现变形.错位的情况,于是又想到了这个老古董,去它的官网一看,果然N年没更新了! 抱着试试看的心理,下载 ...

  9. mysql 和mssql2016中的json字段相关操作

    Mysql: mysql中有专门的Json字段,不是通用的varchar字段,可以保存key/value对,也可保存value集合. 可以增加.删除.修改Json中的某一字段,查询时可以为条件. 如果 ...

  10. Fiddler自动响应AutoResponder正则匹配

    AutoResponder-Add-Rule Editor 两个文本框,先说第一个: Mathes: 前缀为“EXACT:”表示完全匹配(大小写敏感) 无前缀表示基本搜索,表示搜索到字符串就匹配 前缀 ...