D. Gluttony
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x1, x2, ..., xk} (1 ≤ xi ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different, i. e.

Input

The first line contains one integer n (1 ≤ n ≤ 22) — the size of the array.

The second line contains n space-separated distinct integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the elements of the array.

Output

If there is no such array b, print -1.

Otherwise in the only line print n space-separated integers b1, b2, ..., bn. Note that b must be a permutation of a.

If there are multiple answers, print any of them.

Examples
input
2
1 2
output
2 1 
input
4
1000 100 10 1
output
100 1 1000 10
Note

An array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.

Note that the empty subset and the subset containing all indices are not counted.

题目大意:给定一个数组a,将a中的元素调换位置变成b数组,使得对于每一个下标子集,a中对应下标的元素和不等于b中对应下标的元素和.

分析:构造题.如果第i位的数是第j大的,那么就把第j+1大的放在第i位,如果已经是最大的了,就把最小的放在第i位,这样一定是对的.证明的话就是看是否选最大的那个数.

这个数据范围真的是让人分分钟想到状压......

#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, a[]; struct node
{
int x, id;
}e[]; bool cmp(node a, node b)
{
return a.x < b.x;
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
scanf("%d", &e[i].x);
e[i].id = i;
}
sort(e + , e + + n, cmp);
for (int i = ; i <= n; i++)
a[e[i].id] = i;
for (int i = ; i <= n; i++)
{
int t = (a[i] + ) % n;
if (t == )
t = n;
printf("%d ", e[t].x);
} return ;
}

Codeforces 892 D.Gluttony的更多相关文章

  1. codeforces 892 - A/B/C

    题目链接:https://cn.vjudge.net/problem/CodeForces-892A Jafar has n cans of cola. Each can is described b ...

  2. Codeforces 892 C.Pride

    C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. Codeforces 892 B.Wrath

    B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  4. Codeforces 892 A.Greed

    A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony

    A  链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...

  6. Codeforces 891B - Gluttony

    891B - Gluttony 题意 给出一个数字集合 \(a\),要求构造一个数组 \(b\) 为 \(a\) 的某个排列,且满足对于所有下标集合的子集 \(S=\{x_1,x_2,...,x_k\ ...

  7. Gluttony CodeForces - 892D (构造,思维)

    题面: You are given an array a with n distinct integers. Construct an array b by permuting a such that ...

  8. Codeforces 892C/D

    C. Pride 传送门:http://codeforces.com/contest/892/problem/C 本题是一个关于序列的数学问题——最大公约数(GCD). 对于一个长度为n的序列A={a ...

  9. CF892D—Gluttony(思维,好题)

    http://codeforces.com/contest/892/problem/D D. Gluttony You are given an array a with n distinct int ...

随机推荐

  1. Data Center Manager Leveraging OpenStack

    这是去年的一个基于OpenStack的数据中心管理软件的想法. Abstract OpenStack facilates users to provision and manage cloud ser ...

  2. 10道有关ios的题

    1.你使用过Objective-C的运行时编程(Runtime Programming)么?如果使用过,你用它做了什么?你还能记得你所使用的相关的头文件或者某些方法的名称吗? 2.你实现过多线程的Co ...

  3. 云原生技术图谱 (CNCF Landscape)

    转自:https://raw.githubusercontent.com/cncf/landscape/master/landscape/CloudNativeLandscape_latest.jpg

  4. Android(java)学习笔记186:多媒体之视频播放器

    1. 这里我们还是利用案例演示视频播放器的使用: (1)首先,我们看看布局文件activity_main.xml,如下: <RelativeLayout xmlns:android=" ...

  5. DFS、BFS和Backtracking模板

    区别与联系 区别 DFS多用于连通性问题因为其运行思想与人脑的思维很相似,故解决连通性问题更自然,采用递归,编写简便(但我个人不这样觉得...) DFS的常数时间开销会较少.所以对于一些能用DFS就能 ...

  6. selective_search_rcnn.m中代码

    im = imresize(im, [NaN im_width]):把图像转换为宽度为im_width,自动计算列数

  7. 最短路 || POJ 2387 Til the Cows Come Home

    从点N到1的最短路 *记得无向图两个方向都要建边就好了…… 以及多组数据= = #include <iostream> #include <cstdio> #include & ...

  8. Tunnelier使用说明

    Tunnelier与MyEnTunnel类似,但是功能更加强大.MyEnTunnel小巧易用,如何使用MyEnTunnel可以参考 MyEnTunnel使用说明 这里列下Tunnelier的优点: 1 ...

  9. 02numpy

    一. Numpy定义 一个在Python中做科学计算的基础库,重在数值计算,也是大部分PYTHON科学计算库的基础库,多用于在大型.多维数组上执行数值运算 二. Numpy使用 1.创建数组 2.nu ...

  10. linux系统日志中出现大量systemd Starting Session ### of user root 解决

    这种情况是正常的,不算是一个问题 https://access.redhat.com/solutions/1564823 Environment Red Hat Enterprise Linux 7 ...