Last active
December 18, 2015 11:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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