<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 構(gòu)造

      C. Messy

      You are fed up with your messy room, so you decided to clean it up.

      Your room is a bracket sequence s=s1s2…sn of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'.

      In one operation you can choose any consecutive substring of s and reverse it. In other words, you can choose any substring s[l…r]=sl,sl+1,…,sr and change the order of elements in it into sr,sr?1,…,sl.

      For example, if you will decide to reverse substring s[2…4] of string s="((()))" it will be equal to s="()(())".

      A regular (aka balanced) bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

      A prefix of a string s is a substring that starts at position 1. For example, for s="(())()" there are 6 prefixes: "(", "((", "(()", "(())", "(())(" and "(())()".

      In your opinion, a neat and clean room s is a bracket sequence that:

      the whole string s is a regular bracket sequence;
      and there are exactly k prefixes of this sequence which are regular (including whole s itself).
      For example, if k=2, then "(())()" is a neat and clean room.

      You want to use at most n operations to make your room neat and clean. Operations are applied one after another sequentially.

      It is guaranteed that the answer exists. Note that you do not need to minimize the number of operations: find any way to achieve the desired configuration in n or less operations.

      Input

      The first line contains integer number t (1≤t≤100) — the number of test cases in the input. Then t test cases follow.

      The first line of a test case contains two integers n and k (1≤k≤n2,2≤n≤2000, n is even) — length of s and required number of regular prefixes.

      The second line of a test case contains s of length n — the given bracket sequence. It contains only '(' and ')'.

      It is guaranteed that there are exactly n2 characters '(' and exactly n2 characters ')' in the given string.

      The sum of all values n over all the test cases in the input doesn't exceed 2000.

      Output

      For each test case print an answer.

      In the first line print integer m (0≤m≤n) — the number of operations. You do not need to minimize m, any value is suitable.

      In the following m lines print description of the operations, each line should contain two integers l,r (1≤l≤r≤n), representing single reverse operation of s[l…r]=slsl+1…sr. Operations are applied one after another sequentially.

      The final s after all operations should be a regular, also it should be exactly k prefixes (including s) which are regular.

      It is guaranteed that the answer exists. If there are several possible answers you can print any.

      Example

      input
      4
      8 2
      ()(())()
      10 3
      ))()()()((
      2 1
      ()
      2 1
      )(
      output
      4
      3 4
      1 1
      5 8
      2 2
      3
      4 10
      1 4
      6 7
      0
      1
      1 2

      Note

      In the first example, the final sequence is "()(()())", where two prefixes are regular, "()" and "()(()())". Note, that all the operations except "5 8" in the example output are useless (they do not change s).

      題意

      給你一個(gè)長(zhǎng)度為n的括號(hào)序列,恰好n/2個(gè)(,n/2個(gè)),你需要通過(guò)最多n次翻轉(zhuǎn)操作,使得能夠得到恰好k個(gè)合法括號(hào)前綴。

      題解

      首先因?yàn)槟軌蚍D(zhuǎn)n次,所以任何序列我都能得到。

      然后我只要構(gòu)造出來(lái)就行。

      假設(shè)要k個(gè)合法前綴,那么我前k-1個(gè)括號(hào)前綴通過(guò)()()()()()()構(gòu)造,最后的一個(gè)為剩下的括號(hào)((((.....))))這樣構(gòu)造就可以了

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      int n,k;
      string s;
      void solve_swap(int x,int y){
      	while(x<y){
      		swap(s[x],s[y]);
      		x++,y--;
      	}
      }
      string get_str(int n,int k){
      	string tmp="";
      	for(int i=0;i<k-1;i++){
      		tmp+="(";
      		tmp+=")";
      	}
      	int len = n-tmp.size();
      	for(int i=0;i<len/2;i++){
      		tmp+="(";
      	}
      	for(int i=0;i<len/2;i++){
      		tmp+=")";
      	}
      	return tmp;
      }
      void solve(){
      	cin>>n>>k;
      	cin>>s;
      	vector<pair<int,int>>ans;
      	string final_str = get_str(n,k);
      	for(int i=0;i<s.size();i++){
      		if(s[i]!=final_str[i]){
      			for(int j=i+1;j<s.size();j++){
      				if(s[j]==final_str[i]){
      					solve_swap(i,j);
      					ans.push_back(make_pair(i+1,j+1));
      					break;
      				}
      			}
      		}
      	}
      	//cout<<s<<endl;
      	cout<<ans.size()<<endl;
      	for(int i=0;i<ans.size();i++){
      		cout<<ans[i].first<<" "<<ans[i].second<<endl;
      	}
      }
      int main(){
      	int t;
      	scanf("%d",&t);
      	while(t--)solve();
      }
      
      posted @ 2019-11-24 23:07  qscqesze  閱讀(418)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 精品久久免费国产乱色也| 亚洲综合精品香蕉久久网| 成人亚洲国产精品一区不卡| 好吊妞| 国产永久免费高清在线| 热久久这里只有精品99| 亚洲欧洲∨国产一区二区三区| 国产午夜精品福利视频| 欧美精品国产综合久久| 亚洲国产成人久久精品软件| 极品尤物被啪到呻吟喷水| 五月天丁香婷婷亚洲欧洲国产| 116美女极品a级毛片| 实拍女处破www免费看| 国产精品色呦呦在线观看| 亚洲精品无码成人aaa片| 人妻另类 专区 欧美 制服| 岛国一区二区三区高清视频| 产综合无码一区| 国产精品久久毛片| 中文字幕精品亚洲二区| 久久国产精品精品国产色| 精品人妻少妇一区二区三区| 欧洲精品码一区二区三区| 激情国产一区二区三区四区| 国产成人精品亚洲午夜| 久久亚洲av成人无码软件| 久青草视频在线免费观看| 日日爽日日操| 伊人久久久av老熟妇色| 无套内谢极品少妇视频| 熟妇人妻一区二区三区四区| 麻豆文化传媒精品一区观看| 5D肉蒲团之性战奶水欧美| 安徽省| 国产欧美精品一区aⅴ影院| 国产成人AV一区二区三区无码| 无码一区中文字幕| 91老肥熟女九色老女人| 亚洲嫩模一区二区三区| 国产av仑乱内谢|