zoukankan      html  css  js  c++  java
  • CF1227C Messy

    思路:

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

    实现:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int main()
     4 {
     5     int T; cin >> T;
     6     while (T--)
     7     {
     8         int n, k; string s; cin >> n >> k >> s;
     9         vector<pair<int, int>> res;
    10         for (int i = 0; i < n / 2; i++)
    11         {
    12             if (s[i] == '(') continue;
    13             int j = i + 1;
    14             while (j < n && s[j] != '(') j++;
    15             res.push_back(make_pair(i, j));
    16             reverse(s.begin() + i, s.begin() + j + 1);
    17         }
    18         for (int i = 0; i < k - 1; i++)
    19         {
    20             int cur = 2 * i + 1;
    21             int j = cur + 1;
    22             while (j < n && s[j] != ')') j++;
    23             res.push_back(make_pair(cur, j));
    24             reverse(s.begin() + cur, s.begin() + j + 1);
    25         }
    26         cout << res.size() << endl;
    27         for (auto it: res)
    28         {
    29             cout << it.first + 1 << " " << it.second + 1 << endl;
    30         }
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    vs2005 enable your debug
    暑假的安排
    session
    我所看过的电影——不断更新中……
    symbian
    CUDA学习。。。visual assist 扩展
    MySQL密码修改
    fcitx in Fedora
    LDAP身份验证
    mysql自增auto_increment删除记录
  • 原文地址:https://www.cnblogs.com/wangyiming/p/11928192.html
Copyright © 2011-2022 走看看