Posted on November 08, 2021

[CP] Approaching Geometry Problems

This week, I will be hosting a session on Geometry at the IIIT-H programming club, where I plan to discuss a few techniques and problems.

At first sight, computational geometry might seem very hard and intimidating. But once you familiarize yourself with some basic tools and tricks, you’ll become a geometry expert! Let’s break the myth “geometry is hard” together!

§ Basics

Suggestions

It is very important to have a clean, well-tested geometry library/template. It is very easy to make minor errors when coding up geometry solutions - precision issues, edge cases, division by zero etc. So a easy-to-use, modular library helps a lot in writing quick and painless solutions.

You do not have to make your own library from scratch. You can just use an existing one (I just use KACTL, with few tweaks), or you can modify them to adapt to your style, add more primitives etc.

Also, using vector geometry makes life a lot simpler, compared to co-ordinate geometry. Dot and cross products etc. make your derivations super simple and clean.

Resources:

Ideas & Tips:

  1. Consider transforming the input
    • moving the origin
    • rotating the axes (change of basis)
    • scaling (be careful of changes to distances!)
    • circles to points (and vice-versa)
  2. Look for invariants and properties
  3. Standard techniques
    • sweep lines
    • convex hull
    • angle sweep
  4. Utilize existing primitives in your library
    • circle-circle intersection?
    • line-circle intersection?
    • polygon-line intersection?
  5. Outline a slow/brute force solution, and look for optimizations.

§ Problems

Warning: These are from team contests. If you plan to practice them virtually later, avoid opening the problem/solution links.

Problem 1

Problem: ICPC WF 2020, Problem C. Domes

Solution: My Blog

Problem 2

Problem: ICPC WF 2020, Problem F. Ley Lines

Solution: My Blog

Problem 3

Problem: 2020-2021 ICPC Latin American Regional Programming Contest, Problem I. Impenetrable Wall
(full contest)

Solution: Editorial Blog, Full Solution

Problem 4 (Bonus)

Problem: ICPC WF 2020, Problem N. What’s Our Vector, Victor?

Solution: Blog by Franklin_W