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 ;
}
2019-2020 ICPC, Asia Jakarta Regional Contest A. Copying Homework的更多相关文章
- 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 ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)
2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest
目录 Contest Info Solutions A. Copying Homework C. Even Path E. Songwriter G. Performance Review H. Tw ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings
As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC ...
- 2018 ICPC Asia Jakarta Regional Contest
题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 . : 待补 A. Edit Distance Thin ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest C. Even Path
Pathfinding is a task of finding a route between two points. It often appears in many problems. For ...
- 模拟赛小结:2019-2020 ICPC, Asia Jakarta Regional Contest
比赛链接:传送门 离金最近的一次?,lh大佬carry场. Problem A. Copying Homework 00:17(+) Solved by Dancepted 签到,读题有点慢了.而且配 ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest C. Even Path(思维)
Pathfinding is a task of finding a route between two points. It often appears in many problems. For ...
- Asia Jakarta Regional Contest 2019 I - Mission Possible
cf的地址 因为校强, "咕咕十段"队获得了EC-final的参赛资格 因为我弱, "咕咕十段"队现在银面很大 于是咕咕十段决定进行训练. 周末vp了一场, 这 ...
随机推荐
- Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
方法:重启MySQL 在命令行执行: /etc/init.d/mysql start
- 题解 [BZOJ4368][IOI2015]boxes纪念品盒
题面 解析 可以发现,发纪念品有三种方式: 从左边走再原路返回. 从右边走再原路返回. 走一圈. 注意到,第三种走法最多只会走一次, 因为如果走了多次,那发放的物品数量就会>=\(2k\), 那 ...
- hdfs基本使用
基本命令 /usr/local/hadoop/bin/hadoop fs -ls / /usr/local/hadoop/bin/hadoop fs -mkdir /test # 创建目录 /usr/ ...
- 36. ClustrixDB 使用ClustrixDB加密连接
ClustrixDB使用sha256_password插件支持SSL和身份验证. 一些安全规则要求对存储在数据库中的用户密码进行更强的保护.与默认的mysql_native_password插件相比, ...
- P2502 [HAOI2006]旅行 最小生成树
思路:枚举边集,最小生成树 提交:1次 题解:枚举最长边,添加较小边. #include<cstdio> #include<iostream> #include<algo ...
- EnumHelper.cs
网上找的,还比较实用的: using System; using System.Collections.Generic; using System.ComponentModel; using Syst ...
- 第四章 Python数据分析-描述性分析
Python基础统计 统计函数:describe() 常用的统计指标函数: 统计函数 注释 (@数据分析-jacky) size 计算 sum 求和 mean 平均值 var 方差 std 标准差
- 简易学生成绩管理管理系统(java描述)
没正式学过java,但是系统学过C++后,初略的看了下java的基本语法,于是我就尝试着用java来写个简单的学生管理系统,功能不齐全,以后有空再补充吧. 写的时候定义了不同的包名字,如jeaven1 ...
- c++学习之单链表以及常用的操作
新学数据结构,上我写的代码. #include <iostream> #include <cstdlib> using namespace std; typedef int E ...
- 关于centos6版本执行程序报错:libc.so.6: version GLIBC_2.14 not found的解决
执行后程序报错: libc.so.6: version GLIBC_2.14 not found 这种情况是因为当前服务器glibc的版本比较低造成的(不出意外是glibc_2.12是最高版本): 1 ...