Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy

// Since n times may be reversed sequence can be obtained may be composed of any 
#include <the iostream> 
#include < String > 
#include <Vector>
 the using  namespace STD; 
typedef pair < int , int > PII;
 int n, K;
 String S;
 String get_str ( int n-, int K) { // first build the k-1 before 
    String RES = "" ;
     for ( int I = 0 ; I <- K- . 1 ; I ++ ) { 
        RES + = "(";
        res+=")";
    }
    int len=n-res.size();
    for(int i=0; i<len/2; i++)
        res+="(";//构建最后一个 
    for(int i=0; i<len/2; i++)
        res+=")";
    return res;
}
void solve_swap(int x,int y) {
    while(x<y) {
        swap(s[x],s[y]);
        x++,y--;
    }
}
void solve() {
    cin>>n>>k;
    cin>>s;
    vector<PII>res;
    string final_str=get_str(n,k);
    for(int i=0; i<n; i++) {
        if(s[i]!=final_str[i]) {
            for(int j=i+1; j<n; j++) {
                if(s[j]==final_str[i]) {
                    solve_swap(i,j);
                    res.push_back({i+1,j+1});
                    break;
                }
            }
        }
    }
    cout<<res.size()<<endl;
    for(int i=0; i<res.size(); i++)
        cout<<res[i].first<<" "<<res[i].second<<endl;
}
int main() {
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

 

 

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11968013.html