Timus #1604

题目说明:有k种速度,种类1的个数为n1, 种类 2的个数为n2……种类k的个数为nk。对种类进行排序,使得变化的次数最大。eg:
input:
2
2 3
output is not:
1 2 1 2 2
output is:
2 1 2 1 2

题目解析:对所有n进行降序排序,把每种种类保存在一维数组中,利用sub2inedx操作(类似于matlab操作)把二维数组坐标用index表示并输出对应一维数组中的数。
二维数组说明:为了变换次数最大,把最大的种类放在第一列,行数为最大的个数,然后按降序升序一起从上往下从左往右填充剩下的种类并输出。
该算法精髓:sub2index

Problem analysis English version:

  1. Sort signs in descending order
  2. Using one dimensional array to story type.
  3. Output two dimension matrix using sub2index function likely in Matlab program.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

浙ICP备2021019730-1    浙公网安备 33010902002953号
Copyright © 2024 PanCake