2021个人训练赛第9场 问题 B: Permutation Arrays

该博客详细介绍了如何通过指定的指数数组对数据数组进行重排,阐述了一种计算机科学中常见的数据操作方法。文章提供了一个具体的例子,包括输入输出格式,以及解题的AC代码,帮助读者理解如何实现这种数据排列。内容涵盖了数组、索引和排序算法的基础知识,适合编程初学者和进阶者阅读。
摘要由CSDN通过智能技术生成

问题 B: Permutation Arrays

题目描述

In many computer problems, it is necessary to permute data arrays. That is, the data in an array must be re-arranged in some specified order. One way to permute arbitrary data arrays is to specify the permutations with an index array to point out the position of the elements in the new array. Let x be an array that is to be permuted and let x ′be the permuted array. Then, we have the relationship between x and x′that x′pi= xi .

输入

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.
Each input set will contain two lines of numbers. The first line will be an index array p containing the integers 1 . . . n, where n is the number of integers in the list. The numbers in the first line will have been permuted in some fashion. The second line will contain a list numbers in floating point format.

输出

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.
The output for this program will be the list of floating point numbers from the input set, ordered according to the permutation array from the input file. The output numbers must be printed one per line in the same format in which they each appeared in the input file.

样例输入
1

3 1 2
32.0 54.7 -2

样例输出

54.7
-2
32.0

解题思路:

AC代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值