Timus #1444

题目说明:二维数组上有一些点,以第一个点为起点,把剩下的点连起来形成一个没有边相交的多边形,类似于一笔画,无需回到起点,只需把n个点连起来。

题目解析:类似于Timus #1607,极角排序,但排序顺序难想很多。首先找到x轴最小的点作为算法中整个图形的起点。计算每个点的atan2。对atan2进行升序排序,但是其中atan2角度可能相同,你可以画画图想想一下,对相同的距离也进行进行升序排序,距离越大连的越后面。但是我们这道题起点必须为输入的第一个点,这就意味着我们取x轴最小的点作为起的时候需要收尾也要相连,所以如果有大于两个的点位于x轴最小的点的正上方,就会出现收尾不可能相连的错误,这就需要对距离进行降序排序。具体sort函数排序方法可见代码f函数

Problem analysis English version:

  • Find the point with minimum x, exchange it to the first position.
  • Cal atan2.
  • Sort atan2 exclude the point with minimum x which is in the first position.  
  • Find the index which is 1 and output the result.

Difference of sort definition between problem 1207:
Increasing order by theta. When theta is same, use increasing order of the distance from min_x point besides one situation. However if the points have same theta and is directly above the min_x point , we must use descending order of the distance from min_x point.

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.

Timus #1207

题目说明:二维坐标上有一堆点,选两点作为一条直线,把所有点分成两堆

题目解析:极角排序。找到x轴最小的点,其他所有点求atan2,进行排序,取最小点和排列后中间点的index索引输出。

Problem analysis English version:

  • Find minimum x in points.
  • Store atan2 which is theta between minimum x and origin and the index of each point.
  • Use bubble sort to sort atan2 result.
  • Output the index of minimum x and the number in the middle of the series.

代码说明:个人写了冒泡排序,没用c++ sort 和结构体,相对来说代码可读性较差,可以对此进行改进

Timus #1155

题目说明:立方体相邻两点可以同时相加或相减,要把每个点变为0的过程

解题思路:
1. 要有解则A + C + F + H = B + D + E + G
2. 进入循环直至每个点为0
3. 找到最小的位置。如果这个最小的位置旁边3个点都为0,则找到另外一个有数的点,再找这两点分别相邻的相邻的点加1。如果这个最小的位置旁边3个领点有数字,则找一个有数字的点进行相减。(听上去会有点绕)

  • Firstly, if it possible it will satisfy the equation A + C + F + H = B + D + E + G.
  • Secondly, go into loop, if every position is 0 quit the loop.
  • Thirdly, find the maximum position to decrease/increase. If this maximum position doesn’t have adjacent position to decrease, than find another position with value (not 0), increase 1 to two adjacent position adjacent to the maximum position and another position. Else decrease 1 to maximum position and the position adjacent to it.

Timus #2025

题目说明:有n个人分成了k组,不同组的人两两对打,要求对打局数最大。

题目解析:每组约平均得出结果越大,sum过程纯属数学计算过程。

Problem Analysis English version: We can easily notice from math calculations that the more average of each group, the bigger number we will get.

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