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.

Timus #1401

题目说明:给定一个起点,剩下的用L形的三个方块进行填充。

题目解析:迭代。最大的正方形切成四个小正方形,一步步切下去直到最后剩余2*2的小正方形。在大正方形正中间四个方块,除起点所在象限的方块,即另外三个方块标记上相同数字。

Title Analysis English version: We can using iteration to solve problems. From the start position, starting to binary cut the matrix into four pieces until every sub-matrix is 2*2.  I will mark the start position and the other three positions in the middle which has different quadrants besides the quadrant the start position in.

Python matrix 3种解矩阵方程方法

高斯消元法,简单迭代法(Jacobi迭代),高斯迭代法(Gauss-Seidel迭代)。参考文章,该参考文章可以让你明白简单迭代和高斯迭代的方法。
总结:高斯迭代和简单迭代法会遇到矩阵存在解但迭代不收敛的情况,推荐使用高斯消元法。

  1. 高斯消元 O(n3)
  1. 简单迭代 O(k*n2)
  1. 高斯迭代基本思路和简单迭代差不多 O(k*n2)

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