Codeforces Round #668 (Div. 2) A

Codeforces Round #668 (Div. 2) A

/ 0评 / 1663次 / 0

A. Permutation Forgery

Description

给定一个有\(n\)个元素的排列\(p\)。

定义\(F(p)=sort(p_1+p_2,p_2+p_3,……,p_{n-1}+p_n)\)

现请给出任意一个排列\(p^\prime\)有\(F(p)=F(p^\prime)\),但\(p!=p^\prime\)

Input

第一行一个整数\(t\)代表组数

之后每一组由两行构成,第一行为整数\(n\)表示该组有\(n\)个整数,第二行为\(n\)个整数

Output

对于每一组测试用例,输出一组合法的(\p^\prime\)

Analysis

考虑两两元素之和的数组指纹,根据加法交换律\(a+b=b+a\)可以容易得出逆序即为其一组合法解

Accepted Code

/*
 * @Author       : Gehrychiang
 * @LastEditTime : 2020-09-07 09:51:38
 * @Website      : www.yilantingfeng.site
 * @E-mail       : gehrychiang@aliyun.com
 * @ProbTitle    : Permutation Forgery
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T>
void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
template <class T>
void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
int a[105];
int main()
{
    int t;
    _R(t);
    while (t--)
    {
        int n;
        _R(n);
        for (int i = 0; i < n; i++)
        {
            _R(a[i]);
        }
        for (int i = n - 1; i >= 0; i--)
        {
            _W(a[i]);
            _W(" ");
        }
        _W("\n");
    }
    return 0;
}

发表回复

您的电子邮箱地址不会被公开。

你好 No.62251