Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Last active December 18, 2015 11:29
Show Gist options
  • Save sirupsen/5776242 to your computer and use it in GitHub Desktop.
Save sirupsen/5776242 to your computer and use it in GitHub Desktop.
Well-known algorithmic competition hack to represent points in euclidean space as complex numbers to get the distance between them by subtracting the two complex numbers.
#include<complex>
#include<cmath>
#include<iostream>
using namespace std;
typedef complex<double> Point;
#define x imag()
#define y real()
int main()
{
Point p1(5,5);
Point p2(9,2);
cout << abs(p1 - p2) << endl; // Eucledian distance between two points
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment