没啥思路看到题解,先处理最大值发现非常的nice

// Problem: C. Polycarp Recovers the Permutation
// Contest: Codeforces - Codeforces Round 756 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1611/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h&gt;
using namespace std;
using ll=long long;
const int N = 2e5+10;
int a[N];
void solve()
{
	int n;cin&gt;>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(a[1]!=n&amp;&amp;a[n]!=n){
		cout<<-1<<"n";
		return;
	}
	
	for(int i=n;i>=1;--i)cout<<a[i]<<" ";
	cout<<"n";
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;cin>>_;
	while(_--)solve();
	return 0;
}

原文地址:https://blog.csdn.net/m0_60921016/article/details/134823834

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_48808.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注