序列的转置的算法的问题的计算的方式,使用C语言的编程算法技术

Problem Description
Let { A1,A2,...,An } be a permutation of the set{ 1,2,..., n}. If i < j and Ai > Aj then the pair (Ai,Aj) is called an "inversion" of the permutation. For example, the permutation {3, 1, 4, 2} has three inversions: (3,1), (3,2) and (4,2).
The inversion table B1,B2,...,Bn of the permutation { A1,A2,...,An } is obtained by letting Bj be the number of elements to the left of j that are greater than j. (In other words, Bj is the number of inversions whose second component is j.) For example, the permutation:
{ 5,9,1,8,2,6,4,7,3 }
has the inversion table
2 3 6 4 0 2 2 1 0
since there are 2 numbers, 5 and 9, to the left of 1; 3 numbers, 5, 9 and 8, to the left of 2; etc.
Perhaps the most important fact about inversions is Marshall Hall's observation that an inversion table uniquely determines the corresponding permutation. So your task is to convert a permutation to its inversion table, or vise versa, to convert from an inversion table to the corresponding permutation.

Input
The input consists of several test cases. Each test case contains two lines.
The first line contains a single integer N ( 1 <= N <= 50) which indicates the number of elements in the permutation/invertion table.
The second line begins with a single charactor either 'P', meaning that the next N integers form a permutation, or 'I', meaning that the next N integers form an inversion table.

Output
For each case of the input output a line of intergers, seperated by a single space (no space at the end of the line). If the input is a permutation, your output will be the corresponding inversion table; if the input is an inversion table, your output will be the corresponding permutation.

Sample Input
9
P 5 9 1 8 2 6 4 7 3
9
I 2 3 6 4 0 2 2 1 0
0

Sample Output
2 3 6 4 0 2 2 1 0
5 9 1 8 2 6 4 7 3

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

1
求助:原题目是用指针实现矩阵的转置,现在我不知道自己错在哪里了。。。拜托大家帮我看一下
3
C语言:运用指针,输出3*3矩阵的转置阵。大佬们帮忙看看哪里出问题了
2
用不带参数的构造函数,怎么进行矩阵运算
1
跑AlexNet猫狗遇到IndexError: too many indices for array的问题
0
Java语言,实现矩阵的转置的算法怎么实现,怎么按照行列输入矩阵?
1
请各位查看一下c 语言用指针转置为什么失败
0
三元组快速转置函数没有返回值?小白求救
0
应用SVR对负荷数据进行回归分析,测试集出来的数为一条直线?
1
新人求助,对稀疏矩阵进行基本操作时进行两矩阵相加的最后一个输出始终出错?
0
请问我的矩阵转置为什么输出后只把最后一行重复三遍?
2
请问能指点一下矩阵转置和矩阵相加吗?
2
请问为什么我的矩阵输出全为0?
2
为什么要多输入一个数才能运行,我不是规定了数组只有9个数了吗?
2
矩阵转置用指针作为函数参数,为什么输出结果这么奇怪?
2
输入N*N的矩阵,输出它的转置矩阵?
1
MATLAB智能算法第29个案例报错
0
在visual studio编写稀疏矩阵的过程中运行出现“0xC0000005: 读取位置 0x9A696484 时发生访问冲突。”怎么解决?
1
Java语言定义一个4x4的二维数组,然后从键盘输入16个数字构成矩阵,然后将转置矩阵输出出来
1
github上一个js矩阵库的使用问题