A. Permutation Forgery(思维题)

传送门
A. Permutation Forgery
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A permutation of length n
is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4in the array).Let p be any permutation of length n. We define the fingerprint F§ of p as the sorted array of sums of adjacent elements in p More formally,F§=sort([p1+p2,p2+p3,…,pn−1+pn]).For example, if n=4
and p=[1,4,2,3], then the fingerprint is given by F§=sort([1+4,4+2,2+3])=sort([5,6,5])=[5,5,6]You are given a permutation p of length n. Your task is to find a different permutation p′ with the same fingerprint. Two permutations p and p′ are considered different if there is some index i such that pi≠p′i

Input
Each test contains multiple test cases. The first line contains the number of test cases t(1≤t≤668). Description of the test cases follows.
The first line of each test case contains a single integer n(2≤n≤100) — the length of the permutation.The second line of each test case contains n
integers p1,…,pn (1≤pi≤n). It is guaranteed that p is a permutation.

Output
For each test case, output n integers p′1,…,p′n — a permutation such that p′≠p and F(p′)=F§We can prove that for every permutation satisfying the input constraints, a solution exists.
If there are multiple solutions, you may output any.

Example
Input

3
2
1 2
6
2 1 6 5 4 3
5
2 4 3 1 5

Output

2 1
1 2 5 6 3 4
3 1 5 2 4

Note
In the first test case, F§=sort([1+2])=[3]And F(p′)=sort([2+1])=[3]
In the second testcase ,F§=sort([2+1,1+6,6+5,5+4,4+3])=sort([3,7,11,9,7])=[3,7,7,9,11]
And F(p′)=sort([1+2,2+5,5+6,6+3,3+4])=sort([3,7,11,9,7])=[3,7,7,9,11]
In the third test case, F§=sort([2+4,4+3,3+1,1+5])=sort([6,7,4,6])=[4,6,6,7]
And F(p′)=sort([3+1,1+5,5+2,2+4])=sort([4,6,7,6])=[4,6,6,7]

题意:长度n的排列是一个由n个不同的整数组成的数组,从1到n,排列顺序是任意的,输出几组样例,例如p={2,1,6,5,4,3};F§=sort([2+1,1+6,6+5,5+4,4+3])=sort([3,7,11,9,7])=[3,7,7,9,11]
And F(p′)=sort([1+2,2+5,5+6,6+3,3+4])=sort([3,7,11,9,7])=[3,7,7,9,11]
In the third test case, F§=sort([2+4,4+3,3+1,1+5])=sort([6,7,4,6])=[4,6,6,7],则输出一组满足即可p’={2,4,3,1,5};

思路:将输入的样例倒序输出即可。

AC代码

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int t,n,a[110];
    int i;
    cin>>t;
    while(t--)
    {cin>>n;
        for(int i=1;i<=n;i++)
        {cin>>a[i];}
        for(int i=n;i>0;i--)
        {cout<<a[i]<<" ";}
        printf("\n");
    }return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值