16分代码求调
查看原帖
16分代码求调
745048
RadonS楼主2024/10/18 21:31
#include <bits/stdc++.h>
using namespace std;
namespace Radon{
    void Main();
}
int main(){
    Radon::Main();
    return 0;
}

namespace Radon{
    int T;
    int a[1000010];
    int L=1,R;
    int n;
    stack<int>sa,sb;
    bool bol=1;
    int l1,l2,r1,r2;


    void find(){
        int cnt=2;
        while(cnt<=n){
            cnt++;
            cout << l1 << ' ' << r1 << '/' << l2 << ' ' << r2 << ':';
            if(a[l1]==a[r1] && r1-l1+1>=2){
                cout << ":l1r1" << endl;
                sa.push(1);
                sb.push(1);
                l1++;
                r1--;
                continue;
            }
            if(a[l1]==a[l2] && r1-l1+1>=1 && r2-l2+1>=1){
                cout << ":l1l2" << endl;
                sa.push(1);
                sb.push(2);
                l1++;
                l2++;
                continue;
            }
            if(a[l1]==a[r2] && r1-l1+1>=1 && r2-l2+1>=1){
                cout << ":l1r2" << endl;
                sa.push(1);
                sa.push(2);
                l1++;
                r2--;
                continue;
            }
            if(a[r1]==a[l2] && r1-l1+1>=1 && r2-l2+1>=1){
                cout << ":r1l2" << endl;
                sb.push(1);
                sb.push(2);
                r1--;
                l2++;
                continue;
            }
            if(a[r1]==a[r2] && r1-l1+1>=1 && r2-l2+1>=1){
                cout << ":r1r2" << endl;
                sb.push(1);
                sa.push(2);
                r1--;
                r2--;
                continue;
            }
            if(a[l2]==a[r2] && r2-l2+1>=2){
                cout << ":l2r2" << endl;
                sa.push(2);
                sb.push(2);
                l2++;
                r2--;
                continue;
            }
            cout << -1 << endl;
            bol=0;
            break;
        }
        if(bol==0){
            return;
        }
        stack<int>s;
        while(!sa.empty()){
            s.push(sa.top());
            sa.pop();
        }
        while(!s.empty()){
            if(s.top()==1){
                cout << 'L';
            }else{
                cout << 'R';
            }
            // cout << s.top() << ' ';
            s.pop();
        }
        while(!sb.empty()){
            if(sb.top()==1){
                cout << 'L';
            }else{
                cout << 'R';
            }
            // cout << sb.top() << ' ';
            sb.pop();
        }
        cout << endl;
        return;
    }


    void Main(){
        freopen("p7915_2.in","r",stdin);
        freopen("p7915.out","w",stdout);
        ios::sync_with_stdio(0);
        cin.tie(0);cout.tie(0);
        cin >> T;
        while(T--){
            while(!sa.empty()){
                sa.pop();
            }
            while(!sb.empty()){
                sb.pop();
            }
            cin >> n;
            cin >> a[1];
            for(int x=2;x<=2*n;x++){
                cin >> a[x];
                if(a[x]==a[1]){
                    R=x;
                }
            }
            l1=2,r1=R-1,l2=R+1,r2=n*2;
            sa.push(1);
            sb.push(1);
            find();
            cout << "\n____________________________\n";
        }
    }
}
2024/10/18 21:31
加载中...