哪位大佬前来支援(帮忙优化一下)
  • 板块灌水区
  • 楼主lijunye_1
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/5/8 22:32
  • 上次更新2023/10/28 01:51:26
查看原帖
哪位大佬前来支援(帮忙优化一下)
531785
lijunye_1楼主2022/5/8 22:32
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>

using namespace std;
int a[1000005],b[1000005];
int n,q;
int h;
int main(){
	cin>>n>>q;
	a[0]=0;
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+1;
		cin>>b[i];
	}
	int o=max(n,q);
	for(int i=1;i<=o;i++){
		for(int j=1;j<=o;j++){
			if(a[j]==b[i]){
				h=j;
			}
		}
		int w=h;
		w++;
		int e=h;
		e--;
		if(h==n){
			swap(a[h],a[e]);
		}else{
			swap(a[h],a[w]);
		}
		
	}
	for(int i=1;i<=n;i++){
				cout<<a[i]<<" ";
			}
			cout<<endl;
	return 0;
}


2022/5/8 22:32
加载中...