Codeforces Round #607 题解

A title

Sign problem

B title

Greedy only to exchange only the exchange through a minimum string, and then compared with the target sequence

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        string p;
        cin>>s>>p;
        string t=s;
        int fa=0;
        sort(t.begin(),t.end());
        for(int i=0;i<s.size();i++){
            if(t[i]!=s[i]){
                for(int j=s.size()-1;j>i;j--){
                    if(s[j]==t[i]){
                        swap(s[j],s[i]);
                        fa=1;
                        break;
                    }
                }
            }
            if(fa)
            break;
        }
        if(s<p)
        cout<<s<<endl;
        else{
            cout<<"---"<<endl;
        } 
    }
}
View Code

C title

If this question direct violence timeout, so we find that we do not care about the content of the string is greater than X, because it would not be used, then when the string is greater than x when only need to calculate the answer by the formula can be

Note that as we continue to take the mold in the process, it is likely to lead to a negative number, after years of doing problems experience, I found that the modulus is a wonderful thing, so we should try more places plus modulus, prevent errors, and this question should Note explosion int

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        int x;
        cin>>x>>s;
        int i;
        ll ans=s.size();
        for (I = 0 ; I <X; I ++ ) {
             IF (s.size ()> X) { 
                 ANS = (ANS + (ans- (I + . 1 ) + MOD)% MOD * (S [I] - ' . 1 ' )) MOD%; // because ans continues modulo, it may be less than 0 
            }
             the else {
                 IF (S [I] == ' 2 ' ) 
                S + = s.substr (I + . 1 );
                 the else  IF (S [I ] == ' . 3 ' ) 
                S + = s.substr (I + . 1 ) + s.substr (I +1);
                ans=s.size();
            }
        }
        cout<<ans%mod<<endl;
        
    }
}
 
View Code

 

Guess you like

Origin www.cnblogs.com/ctyakwf/p/12237573.html