<补题>
//#include#include #include using namespace std; //对原序列 p *** 作只 *** 作小的数 所以最大值会在最左边或最右边 int n; int a[200200]; int bucket[200200]; int main() { int t; cin >> t; while (t--) { cin >> n; for(int i = 1; i <= n; i ++) cin >> a[i]; //桶里装 a序列各个数的位置 for(int i = 1; i <= n; i ++) bucket[a[i]] = i; // 最大值的位置是否在端点QAQ if(bucket[n] != 1 && bucket[n] != n) cout << -1 << endl; else { vector p; if(bucket[n]==n)//最值在右边 { for(int i=n-1; i>=1; i--) p.push_back(a[i]); p.push_back(a[n]); } else//最值在左边 { for(int i=n; i>1; i--) p.push_back(a[i]); p.push_back(a[1]); } for(int i:p) printf("%d ", i); printf("n"); } } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)