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. vue-resource emulateJSON的作用

    如果Web服务器无法处理编码为application/json的请求,你可以启用emulateJSON选项. 启用该选项后,请求会以application/x-www-form-urlencoded作 ...

  2. POJ1150he Last Non-zero Digit(组合)

    链接 题意从尾部找第一个非0的数 这样就可以考虑下怎样会形成0  这个都知道 只有因子2和因子5相遇会形成0 那这样可以先把所有的2和5先抽出来,这样就保证了其它的数相乘就不会再出现0了 这样就可以转 ...

  3. jmeter配置mysql数据库步骤

    安装环境: Windows10系统 jmeter版本:3.0版本 java1.8版本 安装步骤: 1.下载连接mysql数据库jar包,地址:http://download.csdn.net/deta ...

  4. vs 2015 编译cocos2dx 报错

    VS 2015 compiling cocos2d-x 3.3 error “fatal error C1189: #error: Macro definition of snprintf confl ...

  5. Git-远程操作

    远程分支:远程跟踪分支remote branch是对远程分支状态的引用,是不能移动的,它会根据远程分支变化以及网络通信自动移动.Git服务器包含了远程分支master,在My Computer中的re ...

  6. IOS状态栏

    IOS状态栏是什么地方? 它是IOS设备屏幕顶部显示信号以及电池的区域.状态栏默认的高度是20像素,状态栏在软件开发中有何作用?联网应用中可在自动帮用户下载数据时使用,推荐在状态栏中予以显示.状态栏可 ...

  7. $.noconflict() 有什么用处

    jQuery默认使用"$"操作符,prototype等其他框架也是是使用"$",于是,如果jQuery在其他库之后引入,那么jQuery将获得"$&q ...

  8. promise 里面的 console.info 打印信息 并不准确,后期有修改对象数据,会覆盖,影响之前的显示

    promise 里面的 console.info 打印信息 并不准确,后期有修改对象数据,会覆盖,影响之前的显示

  9. easyui实现增删改查

    陈旧的开发模式 美工(ui工程师:出一个项目模型) java工程师:将原有的html转成jsp,动态展示数据 缺点: 客户需要调节前端的展示效果 解决:由美工去重新排版,重新选色. 前后端分离: 前端 ...

  10. 暑假集训 || 概率DP

    Codeforces 148D 考虑状态转移..https://www.cnblogs.com/kuangbin/archive/2012/10/04/2711184.html题意:原来袋子里有w只白 ...