Блог пользователя abzaloid

Автор abzaloid, 12 лет назад, По-русски

Всем привет!

Задача с одной из областных олимпиад: Даны N различных точек (xi, yi). Нужно найти кол-во различных прямоугольных треугольников, вершинами которых являются точки (xi, yi).

Ограничения: N ≤ 5000, |xi|, |yi| ≤ 104

timelimit: 2s, memorylimit = 64MB

Спасибо

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

Denote a right triangle as with the right angle at vertex . Try choosing each point as . Sort the other points by angle around it, then try choosing each point as (in sorted order) and use 2 pointers to keep the range of points which are at 90° to it (candidates for ). Time: due to sorting.

Can be improved to O(N2) — if we choose , there are just N interesting lines (the ones perpendicular to some ), and we need to count the points lying on each of them; that can be achieved using hashmaps.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I've come up with some ideas that tell me that this problem should be solvable in O(n2). I'll describe the solution when it'll be ready.