思路:

构造题。首先把字符串变成“(((((...)))))”的样子,再根据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. Linux 查看系统配置参数

    原文链接:http://www.cnblogs.com/aric2016/p/10971690.html 查看 cpu信息: cat /proc/cpuinfo 查看内存信息: grep MemTot ...

  2. NOIP刷题

    搜索 [NOIP2013]华容道 最短路+带剪枝的搜索,是一个思维难度比较大的题目. CF1064D Labyrinth 考虑贪心,用双向队列bfs [NOIP2017]宝藏 剪枝搜索出奇迹 题解:h ...

  3. 搭建自己的博客(七):使用bootstrap框架美化导航栏

    前面发现自己写css代码以及很多功能太麻烦,故希望在自己的博客中引入bootstrap框架,bootstrap是一个非常强大的前端框架,简单易学容易上手.附上官网地址:bootstrap官网 我使用的 ...

  4. python中如何给散点图上面的特定点做标记

    今天想在散点图的某些特定的点外面画圆圈标记,从下面的文章找到一些灵感,只要在原来的散点图上面给指点添加相应的标志,设置其透明度就可以实现该想法. 顺便复习下散点图的用法. 大家平时为了直观地显示数据的 ...

  5. springBoot学习(二):初学JPA

    依旧跟着大佬学习JPA,在这里记下过程. JPA主要做的事情是简化数据库操作,至少现在为止,我觉得还是挺方便简单明了的.在原本代码的基础下,更改UserController.User.UserRepo ...

  6. java 通过runtime 调用python 不显示python运行内容的bug

    先说下上面问题的原因,上面问题是因为python中用到了第三方的类库,你的电脑上没有那个类库,所以程序没有运行,在控制台也就看不到输出.只要导入那个类库就好... python 导入类库,可以单独下载 ...

  7. These dependencies were not found: *!!vue-style-loader!css-loader?

    在vue中使用less首先要下载依赖:npm install less less-loader --save-dev 下载好之后就可以.vue文件中使用lang="less"和@i ...

  8. python笔记9 线程进程 threading多线程模块 GIL锁 multiprocessing多进程模块 同步锁Lock 队列queue IO模型

    线程与进程 进程 进程就是一个程序在一个数据集上的一次动态执行过程.进程一般由程序.数据集.进程控制块三部分组成.我们编写的程序用来描述进程要完成哪些功能以及如何完成:数据集则是程序在执行过程中所需要 ...

  9. Android插件化(二):OpenAtlas插件安装过程分析

    Android插件化(二):OpenAtlas插件安装过程分析   转 https://www.300168.com/yidong/show-2788.html   核心提示:在前一篇博客 Andro ...

  10. It’s worth noting值得注意的是

    It’s worth noting that in JavaScript applications the Model is often connected via Ajax to a back-en ...