UKE?????前天一直在Waiting
查看原帖
UKE?????前天一直在Waiting
317400
Foggy_night楼主2023/4/4 12:27
#include <bits/stdc++.h>
using namespace std;
int a[1005],b[1005],c[1005],d[1005];
int main(){
	int t;
    cin >> t;
    while(t--){
    	int n;
        cin >> n;
        for(int i = 1; i <= n; i++){
			cin >> a[i];
			c[i] = a[i];
		} 
        for(int i = 1; i <= n; i++){
        	cin >> b[i];
			d[i] = b[i];
		}
        sort(c+1, c+n+1);
		sort(d+1, d+n+1);
		bool flag = true; 
        for(int i = 1; i <= n; i++)
        	if(c[i] != d[i]){
        		cout << "NO" << endl;
        		flag = false;
			}
		if(flag = false)
			continue;
        cout << "YES" << endl;
        for(int i = 1; i <= n; i++){
            int x = 0;
            for(int j = i;j <= n; j++){
                if(a[j] == b[i]){ 
                    x = j;
                    break;
                }
            }
            for(int j = x; j > i; j--){
                cout << j << ' ' << j-1 << endl;
                swap(a[j], a[j-1]);
            }
        }
        cout << "0 0" << endl;
    }
    return 0;
}
2023/4/4 12:27
加载中...