思路:

构造题。首先把字符串变成“(((((...)))))”的样子,再根据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. vue生命周期在工作中的用法

    1.首先来官方服生命=周期的解释: beforeCreate():实例在内存中被创建出来,还没有初始化好data和methods属性. create():实例已经在内存中创建,已经初始化好data和m ...

  2. PHP 连接MySQL

    连接MySQL 在我们访问MySQL数据库前,我们需要先连接到数据库服务器: 实例(MySQLi - 面向对象) <?php $servername = "localhost" ...

  3. Linux FC/iSCSI存储设备管理系列(一):Linux系统设备驱动入门

    Linux FC/iSCSI存储设备管理系列(一):Linux系统设备驱动入门 转载请在文首保留原文出处:EMC中文支持论坛 - https://community.emc.com/go/chines ...

  4. 7、transformation和action2

    一.transformation开发实战 1.map: 将集合中每个元素乘以2 使用map算子,将集合中的每个元素都乘以2 map算子,是对任何类型的RDD,都可以调用的,在Java中,map算子接收 ...

  5. linux经常用的命令

    常用 安装包   centos   yum    /   Ubuntu  Debian  apt-get clear :清空终端       [cmd 下是cls] vi/vim  编辑器    详情 ...

  6. 构造器Constructor

    构造器Constructor是否可被override构造器Constructor不能被继承,因此不能重写Overriding,但可以被重载Overloading 首先,构造器是不能被继承的,因为每个类 ...

  7. 十一月百度杯pwnme 详细wp

    目录 程序基本信息 程序溢出点 整体思路 exp脚本 成功获得flag 参考 程序基本信息 可以看到开启了栈不可执行和got表不可写保护. 程序溢出点 在函数sub_400AF7中,v8可以读入0x1 ...

  8. 当前主流的小型嵌入式 GUI

    当前主流的嵌入式 GUI当前主流的小型嵌入式 GUI 主要有:emWin(uCGUI),TouchGFX,Embedded Wizard GUI,uGFX 和 MicroChip GUI. 当然,还有 ...

  9. RVS PA-1800 功放参数

        RVS PA-1800大功率功放技术参数:     文章来源:外星人来地球 欢迎关注,有问题一起学习欢迎留言.评论

  10. openstack 基镜像展开过程