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.
不知道这套题有多少人做。
这个题意是说找一个排列,始与原排列的差的绝对值大于N,我们每个排列都选跟他差最大的 也就是(1->n),(2->n-1).....
直接输出n+1-a[i]即可。
#include<iostream>
using namespace std;
int a[10000000];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cout<<((n+1)-a[i])<<' ';
}
好久没见过这么短的代码了
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 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 (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 签到,读题有点慢了.而且配 ...
- Asia Jakarta Regional Contest 2019 I - Mission Possible
cf的地址 因为校强, "咕咕十段"队获得了EC-final的参赛资格 因为我弱, "咕咕十段"队现在银面很大 于是咕咕十段决定进行训练. 周末vp了一场, 这 ...
随机推荐
- 2017蓝桥杯算式900(C++C组)
题目:算式900 小明的作业本上有道思考题: 看下面的算式: (□□□□-□□□□)*□□=900 其中的小方块代表0~9的数字,这10个方块刚好包含了0~9中的所有数字. 注意:0不能作为某 ...
- String 对象-->charCodeAt() 方法
1.定义和用法 获取指定下标的字符的ASCII码(Unicode) 返回值:0~65535之间的整数 语法: string.charCodeAt(index) 参数: index:指定字符的下标 举例 ...
- 小猪佩奇C代码实现
// ASCII Peppa Pig by Milo Yip #include <stdio.h> #include <math.h> #include <stdlib. ...
- matplotlib BboxBase类
2020-04-07 17:24:12 --Edit by yangray BboxBase 是 TransformNode 的子类, 同时它是所有 bounding box(平行四边形限位框) 的 ...
- 11-Json提取器使用
1.使用json提取关键信息 有时候接口返回数据为json数据或者直接为一个列表,可使用这个更简单快捷 json数据: 这样的,数据有在result里面以列表形式存在,也有在列表外的,可在json提取 ...
- 邮件退信“Remote Server returned '420 4.2.0 Recipient deferred because there is no Mdb'”
标题是一个近期遇到的NDR 对于Exchange运维工作者,NDR通常给了我们较为清晰的排错方向,我们先看一下退信的原因, 我的一台MailBox报错“远程服务器返回‘420 4.2.0’接受延迟,因 ...
- 漏洞复现环境集锦-Vulhub
0x01 Vulhub简介 Vulhub是一个面向大众的开源漏洞靶场,无需docker知识,简单执行两条命令即可编译.运行一个完整的漏洞靶场镜像. 0x02 安装 # 安装pip curl -s ht ...
- c++学习day01基础知识学习
一.代码示例解析: #include <iostream> int main() { using namespace std; cout << "come up an ...
- Jar包一键重启的Shell脚本及新服务器部署的一些经验
原文首发于博客园,作者:后青春期的Keats:地址:https://www.cnblogs.com/keatsCoder/ 转载请注明,谢谢! 前言 最近公司为客户重新部署了一套新环境,由我来完成了基 ...
- [html][javascript] 关于SVG环形进度条
下面是个例子: <style> .demo2{ transform-origin: center; transform: rotate(-90deg); transition: strok ...