Codeforces Round #594 (Div. 2) D1 - The World Is Just a Programming Task (贪心)

 

 Idea: enumerate change of position i, j then we must first determine whether to change the sequence of exact match if possible then we need to change over the difference between the maximum position and then directly on the line judge

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 1e5+7;
typedef long long ll;
const ll mod = 1e9+7;
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; string s;
     cin>>n; cin>>s;
     int ans=0;
     int l,r;
     l=r=0;
     for(int i=0;i<n;i++)
         for(int j=i;j<n;j++){
             swap(s[i],s[j]);
             int cnt=0;
             int minn=0;
             for(int k=0;k<n;k++){
                 if(s[k]=='(') Cnt ++ ;
                else cnt-- ; 
                Minn = min (Minn, cnt);    
            } 
            Int no = 0 ;
            if (cnt == 0 ) {
                 for ( int k = 0 ; k <n; k ++ ) {
                     if (s [k] == ' ( ' ) cnt ++ ;
                     else cnt-- ;
                     if (cnt == Minn) nothing ++ ; 
                } 
            } 
            if (res> years) {
                ans=res;
                l=i; r=j;
            }
            swap(s[i],s[j]);
         }
        cout<<ans<<endl;
        cout<<l+1<<" "<<r+1<<endl;
    return 0;
} 
View Code

 

Guess you like

Origin www.cnblogs.com/wmj6/p/11709992.html