CF1227C Messy
思路:
构造题。首先把字符串变成“(((((...)))))”的样子,再根据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的更多相关文章
- IOI2016Day2. Messy
题目链接:http://uoj.ac/problem/239 题目大意: 这是一道交互题,交互库维护了一个数据结构,可以存储n为二进制串,一开始你可以向空的数据结构中插入若干二进制串, 接下来这个数据 ...
- 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 ...
- the solution about "messy code" in elicpse
I use the Elicpse IDE to develope the ansdroid app.Sometime encounter the messy code in the Elicpse ...
- 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: / ...
- 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 ...
- .net 中文显示乱码问题(Chinese display with messy code)
Case:同样的代码,本地开发环境(local is Chinese Simplify)可以成功运行,但是放到Windows Server 2008 R2(Local is United State) ...
- 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; # ...
- IS Kali: installed chiess messy code problem
apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy init 6
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy
//因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> us ...
随机推荐
- 第五章 CSS美化网页元素
一.span标签:能让某几个文字或者某个词语凸显出来 <p> 今天是11月份的<span>第一天</span>,地铁卡不打折了 </p> 二.字体风格 ...
- sublime 分屏显示 不是插件
点击 view--layout --- 选择几屏即可(single / columns 2 ....) 快捷键 Alt + Shift + 1/2/3/4 分别对应1 ,2,3,4屏 如何把一个文 ...
- Vue IE11 报错 Failed to generate render function:SyntaxError: 缺少标识符 in
报错截图: 查了篇文章(https://blog.csdn.net/weixin_42018057/article/details/81385121),遇到的情况跟文章里描述的类似,他提供的方法是:需 ...
- Linux 内核参数说明
转载自: https://www.cnblogs.com/tolimit/p/5065761.html 因个人能力有限,不能保证所有描述都正确,还请大家集思广益,有错误的地方欢迎大家留言指正,同时也欢 ...
- 斜率dp的模板总结
#include<cstdio> #include<algorithm> using namespace std; long long sumt[40005],sum[4000 ...
- 使用Keras训练神经网络备忘录
小书匠深度学习 文章太长,放个目录: 1.优化函数的选择 2.损失函数的选择 2.2常用的损失函数 2.2自定义函数 2.1实践 2.2将损失函数自定义为网络层 3.模型的保存 3.1同时保持结构和权 ...
- 带你了解HTTP协议(一)
本篇文章篇幅比较长,先来个思维导图预览一下. 一张图带你看完本篇文章 一.概述 1.计算机网络体系结构分层 计算机网络体系结构分层 2.TCP/IP 通信传输流 利用 TCP/IP 协议族进行 ...
- PHP 之Html标签转义与反转义
1.htmlentities()函数转义html 2.html_entity_decode()函数反转义html 我这里是用来反转义富文本编辑器的内容
- 简记webpack运行报错 Uncaught TypeError: self.postMessage is not a function
说好2017Fix的还是能重现,可能项目的版本比较旧了,简要记录解决办法 1.错误: index.js?bed3:67 Uncaught TypeError: self.postMessage is ...
- GO 包相关
1 包编译,eg: 引用pkgtest包 pkgtest包没有任何编译,项目直接导入引用,项目编译时实际是会编译pkgtest并在pkg\windows_386下生成pkgtest.a文件 再编译项目 ...