Created
April 3, 2015 07:14
-
-
Save grapefroot/111b9655f5c08b55a415 to your computer and use it in GitHub Desktop.
acmp 232
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 <vector> | |
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
struct pt { | |
double x, y; | |
pt operator- (pt p) { | |
pt res = { x - p.x, y - p.y }; | |
return res; | |
} | |
}; | |
struct circle : public pt { | |
double r; | |
circle() { | |
x = 0; | |
y = 0; | |
r = 0; | |
} | |
circle(double _x, double _y, double _r) { | |
x = _x; | |
y = _y; | |
r = _r; | |
} | |
}; | |
struct line { | |
double a, b, c; | |
}; | |
const double EPS = 1E-9; | |
double sqr(double a) { | |
return a * a; | |
} | |
void tangents(pt c, double r1, double r2, vector<line> & ans) { | |
double r = r2 - r1; | |
double z = sqr(c.x) + sqr(c.y); | |
double d = z - sqr(r); | |
if (d < -EPS) return; | |
d = sqrt(abs(d)); | |
line l; | |
l.a = (c.x * r + c.y * d) / z; | |
l.b = (c.y * r - c.x * d) / z; | |
l.c = r1; | |
ans.push_back(l); | |
} | |
vector<line> tangents(circle a, circle b) { | |
vector<line> ans; | |
for (int i = -1; i <= 1; i += 2) | |
for (int j = -1; j <= 1; j += 2) | |
tangents(b - a, a.r*i, b.r*j, ans); | |
for (size_t i = 0; i<ans.size(); ++i) | |
ans[i].c -= ans[i].a * a.x + ans[i].b * a.y; | |
return ans; | |
} | |
#define DEBUG | |
int main() { | |
int numberOfPoints; | |
ifstream fileInput("input.txt"); | |
#ifdef DEBUG | |
cout << fileInput.is_open() << endl; | |
#endif | |
fileInput >> numberOfPoints; | |
vector<circle> trees(numberOfPoints); | |
double x = 0, | |
y = 0, | |
r = 0; | |
for (size_t i = 0; i < numberOfPoints; ++i) { | |
fileInput >> x >> y >> r; | |
trees[i] = circle(x, y, r); | |
} | |
#ifdef DEBUG | |
for (size_t i = 0; i < numberOfPoints; ++i) { | |
cout << trees[i].x << " " << trees[i].y << " " << trees[i].r << endl; | |
} | |
#endif | |
for (size_t i = 0; i < numberOfPoints; ++i) { | |
for (size_t j = 0; j < numberOfPoints; ++j) { | |
vector<line> tang = tangents(trees[i], trees[j]); | |
for (size_t k = 0; k < numberOfPoints; ++k) { | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment