Codeforces 892 D.Gluttony
2 seconds
256 megabytes
standard input
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.
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.
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.
2
1 2
2 1
4
1000 100 10 1
100 1 1000 10
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的更多相关文章
- codeforces 892 - A/B/C
题目链接:https://cn.vjudge.net/problem/CodeForces-892A Jafar has n cans of cola. Each can is described b ...
- Codeforces 892 C.Pride
C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces 892 B.Wrath
B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces 892 A.Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony
A 链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...
- Codeforces 891B - Gluttony
891B - Gluttony 题意 给出一个数字集合 \(a\),要求构造一个数组 \(b\) 为 \(a\) 的某个排列,且满足对于所有下标集合的子集 \(S=\{x_1,x_2,...,x_k\ ...
- Gluttony CodeForces - 892D (构造,思维)
题面: You are given an array a with n distinct integers. Construct an array b by permuting a such that ...
- Codeforces 892C/D
C. Pride 传送门:http://codeforces.com/contest/892/problem/C 本题是一个关于序列的数学问题——最大公约数(GCD). 对于一个长度为n的序列A={a ...
- CF892D—Gluttony(思维,好题)
http://codeforces.com/contest/892/problem/D D. Gluttony You are given an array a with n distinct int ...
随机推荐
- [转]MVC 检测用户是否已经登录
本文转自:http://blog.csdn.net/jayzai/article/details/41252137 当我们访问某个网站的时候需要检测用户是否已经登录(通过Session是否为null) ...
- 【Laravel】 常用命令
自动创建项目 laravel new || laravel new xxx || composer create-project --prefer-dist laravel/laravel blog ...
- Java程序操作数据库SQLserver详解
数据库基本操作:增删改查(CRUD) crud介绍(增.删.改.查操作) CRUD是指在做计算处理时的增加(Create).查询(Retrieve)(重新得到数据).更新(Update)和删除(Del ...
- 一条陌生的出路【过往d心声】
一条陌生的出路 Vashon的心声 人生就像一列车,车上总有形形色色的人穿梭往来.你也可能会在车上遇到很多你以为有缘分的人,但是车也会有停下来的时候,总会有人从人生这列车上上下下,当你下去的时候你挥挥 ...
- PHP一句话后门过狗姿势万千之理论篇
写在前面: 过狗相关的资料网上也是有很多,所以在我接下来的文章中,可能观点或者举例可能会与网上部分雷同,或者表述不够全面. 但是我只能说,我所传达给大家的信息,是我目前所掌握或者了解的,不能保证所有人 ...
- Oracle的Central Inventory和Local inventory详解
很多朋友对Oracle的inventory信息不太了解以至遇到相关的问题不知道如何处理,这篇文章我们将详细讲解Oracle的Central Inventory (oraInventory)和Local ...
- Android(java)学习笔记161:开发一个多界面的应用程序之人品计算器的简单实现
1.开启新的Activity的方法: (1)Intent 意图 (2)intent.setAction("自定义") 记得在清单文件中声明 (3)intent.setData(前 ...
- JavaScript-条件循环
JavaScript-条件循环 条件判断语句 if 语句 - 只有当指定条件为 true 时,使用该语句来执行代码 if (表达式){ 当条件为 true 时执行的代码} if...else 语 ...
- win7下自动更新svn目录
!!注意,文件编码必须是ANSI.否则中文路径会乱码 ::这里是svn安装目录 set svnExe="C:\Program Files\TortoiseSVN\bin\TortoisePr ...
- Linux下scp报Permission denied错误的解决方法
sudo vim /etc/ssh/sshd_config 把PermitRootLogin no改成PermitRootLogin yes如果原来没有这行或被注释掉,就直接加上PermitRootL ...