2019-2020 ICPC, Asia Jakarta Regional Contest A. Copying Homework
Danang and Darto are classmates. They are given homework to create a permutation of N integers from 1 to N. Danang has completed the homework and created a permutation A of N integers. Darto wants to copy Danang's homework, but Danang asks Darto to change it up a bit so it does not look obvious that Darto copied.
The difference of two permutations of N integers A and B, denoted by diff(A,B), is the sum of the absolute difference of Ai and Bi for all i. In other words, diff(A,B)=ΣNi=1|Ai−Bi|. Darto would like to create a permutation of N integers that maximizes its difference with A. Formally, he wants to find a permutation of N integers Bmax such that diff(A,Bmax)≥diff(A,B′) for all permutation of N integers B′.
Darto needs your help! Since the teacher giving the homework is lenient, any permutation of N integers B is considered different with A if the difference of A and B is at least N. Therefore, you are allowed to return any permutation of N integers B such that diff(A,B)≥N.
Of course, you can still return Bmax if you want, since it can be proven that diff(A,Bmax)≥N for any permutation A and N>1. This also proves that there exists a solution for any permutation of N integers A. If there is more than one valid solution, you can output any of them.
Input
Input begins with a line containing an integer: N (2≤N≤100000) representing the size of Danang's permutation. The next line contains N integers: Ai (1≤Ai≤N) representing Danang's permutation. It is guaranteed that all elements in A are distinct.
Output
Output in a line N integers (each separated by a single space) representing the permutation of N integers B such that diff(A,B)≥N. As a reminder, all elements in the permutation must be between 1 to N and distinct.
Examples
input
4
1 3 2 4
output
4 2 3 1
input
2
2 1
output
1 2
Note
Explanation for the sample input/output #1
With A=[1,3,2,4] and B=[4,2,3,1], diff(A,B)=|1−4|+|3−2|+|2−3|+|4−1|=3+1+1+3=8. Since 8≥4, [4,2,3,1] is one of the valid output for this sample.
解题思路j:题目要求的是将数组元素重新排列,使得对应位置上的元素相减和的绝对值最大,即保证最大程度每一位上的元素都不同,将第一位对应最后一位,第二位对应倒数第二位,...。
AC代码:
#include <iostream>
using namespace std;
int main()
{
int n,a;
while(cin>>n)
{
for(int i=;i<=n;i++)
{
cin>>a;
cout<<n-a+<<" ";
}
cout<<endl;
}
return ;
}
最新文章
- Struts——(四)异常处理机制
- Python札记 -- 使用easy_install进行模块/包管理
- iNeedle系统之国舜项目
- 十天来学习java的心得体会
- Redis - hash类型操作
- OC 加密
- 两个基于C++/Qt的开源WEB框架
- 关于使用cocoaPods,import导入时第三方库头文件没有提示问题的解决办法
- 作业:汽车查询--弹窗显示详情,批量删除 ajax做法(0521)
- java设计模式之 单例模式 Singleton
- 阅读 - Code Complete 2 - 第33章 - 个人性格
- jumpserver v0.4.0 基于 CenOS7 的安装详解
- 使用jvisualvm来远程观察Java程序及jvisualvm插件[转]
- 在开启kerberos 后,hbase存在数据命名空间的问题(解决方案)
- 关于Linux虚拟化技术KVM的科普
- 如何在eclipse中快速debug到想要的参数条件场景下
- Django rest framework 源码分析 (1)----认证
- <;a>;标签的特殊和文本的样式
- BCP文件导入SQLServer数据库遇到的问题
- MySQL DDL--ghost执行模板和参数
热门文章
- barcode模块: plus.barcode.scan 进行扫描图片出现无法识别二维码,打印的错误信息是code:8,message:&#39;&#39;
- Java8-Stream-No.07
- 自己总结:汇编CALL和RET指令
- Noip2016 提高组 Day1
- python 生成金字塔
- python获取hive表时间格式最大分区
- Netfilter 之 iptable_mangle
- postgreSQL计算总数sum if case when
- PyTorch中使用深度学习(CNN和LSTM)的自动图像标题
- HelloWorld入门代码