[Offer收割]编程练习赛19 register

Ended

Participants:405

Verdict:Time Limit Exceeded
Score:80 / 100
Submitted:2017-07-23 13:51:27

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
int solve(){
    string s;cin>>s;
    int n = s.size();
    string tar = "";
    for(int i=1;i<=n;i++){
        tar+=(char)('0'+i);
    }
    //cout<<tar<<endl;
    queue<string> q;
    set<string> vis;
    vis.insert(s);
    if(s==tar)return 0;
    int ret = 0;
    q.push(s);
    while(!q.empty()){
        int qn = q.size();
        //cout<<ret<<endl;
        ret++;  
        for(int k=0;k<qn;k++){
            string ss = q.front();
            q.pop();
            for(int i=0;i<n-1;i++){ //n is the length of the string
                string adder = ss.substr(i,2);
                string rmr = ss.substr(0,i);
                if(i+2<n) rmr+=ss.substr(i+2);
                for(int p=0;p<rmr.size()+1;p++){    //p is the place
                    string news = rmr.substr(0,p);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX