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 ...
随机推荐
- window上安装MySQL
一.安装MySQL 1.1 下载解压缩版的安装包,解压,然后配置环境变量 PATH=.......;D:\Program Files (x86)\mysql-5.5.27-win32\bin (注意是 ...
- .NET Core WebAPI Swagger使用
相对于普通的webapi而言,.net core webapi本身并不具备文档的功能,所以可以借助第三方插件:swagger,使用的话很简单. 步骤一. Nuget Packages安装,使用程序包管 ...
- viewport实现html页面动态缩放/meta viewport/viewport
页面默认缩放比例为1,最小宽度为375px,在小于375px出现水平滚动条的时候重新计算显示比例缩小界面, <!DOCTYPE html> <html lang="en&q ...
- iOS infoq资料架构设计漫谈
http://www.infoq.com/cn/ios/?utm_source=infoq&utm_medium=header_graybar&utm_campaign=topic_c ...
- Really simple SSH proxy (SOCKS5)
原文: https://thomashunter.name/blog/really-simple-ssh-proxy-socks5/ SOCKS5 is a simple, eloquent meth ...
- mac下elasticsearch安装部署
下载elaticsearch集成包 优势:封装了对插件的支持,且安装方式较简单 地址:https://github.com/medcl/elasticsearch-rtf 解压到指定目录后,获取该集成 ...
- PMP项目管理学习笔记(4)——项目整合管理
六个整合管理过程. 1.制定项目章程 一个新项目要完成的第一件事,就是项目章程的制定.这是授权你开展工作的文档.不过并不总是需要你介入,通常情况下会由赞助人交给你.如果没有项目章程,你就没有权利告诉你 ...
- 8.3.3 快速系统调用 —— XP SP3上SystemCallStub的奇怪问题
依书上的例子,ReadFile()函数会调用ntdll!NtReadFile(),后者将服务号放到eax之中,然后调用SharedUserData!SystemCallStub(),由此函数执行sys ...
- Three.js模型隐藏或显示
材质属性.visible查看Three.js文档的基类Material,可以知道材质属性.visible的作用就是控制绑定该材质的模型对象是否可见,默认值是true,LineBasicMaterial ...
- tomcat https协议
一.tomcat证书 JDK自带的keytool工具来生成证书 1. 在jdk的安装目录\bin\keytool.exe下打开keytool.exe 2. 在命令行中输入以下命令: keytool - ...