Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <string>
- #include <deque>
- #include <iomanip>
- #include <map>
- #define F first
- #define S second
- using namespace std;
- const long double eps = 0.0000005;
- const long double eps1 = 1e-5;
- const long double pi = 3.1415926535897932;
- struct point
- {
- double x;
- double y;
- double v;
- point()
- {
- x = 0.0;
- y = 0.0;
- }
- point(double _x, double _y)
- {
- x = _x;
- y = _y;
- }
- };
- struct line
- {
- long double a;
- long double b;
- long double c;
- line()
- {
- a = 0.0;
- b = 0.0;
- c = 0.0;
- }
- line(point _a, point _b)
- {
- a = _b.y - _a.y;
- b = _a.x - _b.x;
- c = b * _a.y - a * _a.x;
- }
- };
- vector < point > d;
- double r;
- point a, b;
- map < point,vector < pair < double, point > > > g;
- point c[4];
- point operator+(point a, point b)
- {
- return point(a.x + b.x, a.y + b.y);
- }
- point operator-(point a, point b)
- {
- return point(a.x - b.x, a.y - b.y);
- }
- point operator*(point a, long double k)
- {
- return point(a.x * k, a.y * k);
- }
- point operator/(point a, long double k)
- {
- return point(a.x / k, a.y / k);
- }
- bool operator<(const point& a, const point& b)
- {
- if (a.x - b.x < -eps || (fabs(a.x - b.x) < eps && a.y - b.y < -eps))
- return true;
- return false;
- }
- bool operator>(const point& a, const point& b)
- {
- if (a.x - b.x > eps || (fabs(a.x - b.x) < eps && a.y - b.y > eps))
- return true;
- return false;
- }
- bool operator==(const point& a, const point& b)
- {
- if (fabs(a.x - b.x) < eps && fabs(a.y - b.y) < eps)
- return true;
- return false;
- }
- long double scal(point a, point b)
- {
- return a.x * b.x + a.y * b.y;
- }
- long double vect(point a, point b)
- {
- return a.x * b.y - a.y * b.x;
- }
- long double dist(point a, point b)
- {
- return sqrt(scal(a - b, a - b));
- }
- point norm(point a)
- {
- return a / sqrt(scal(a, a));
- }
- void cross(point o1, double r1, point o2, double r2, point &c1, point &c2)
- {
- double t = dist(o1, o2);
- point f = o2 - o1;
- f = norm(f);
- double h = r1 * r2 / t;
- double l = sqrt(r1 * r1 - h * h);
- f = f * l;
- point p = o1 + f;
- point n = point(-f.y, f.x);
- n = norm(n);
- n = n * h;
- c1 = p + n;
- c2 = p - n;
- }
- double dist(point p, line l)
- {
- return abs(l.a * p.x + l.b * p.y + l.c) / sqrt(l.a * l.a + l.b * l.b);
- }
- int crossring(line l, point p)
- {
- if ((dist(p, l) - r) < -eps)
- return 2;
- return 1;
- }
- void parkas(point o1, point o2, point &c1, point &c2, point c3, point c4)
- {
- point v = o2 - o1;
- point perp = norm(point(-v.y, v.x)) * r;
- c1 = o1 + perp;
- c2 = o1 - perp;
- c3 = o2 + perp;
- c4 = o2 - perp;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- double x, y;
- cin >> x >> y >> r;
- a = point(x, y);
- cin >> x >> y;
- b = point(x, y);
- for (int i = 0; i < 3; i++)
- {
- cin >> x >> y;
- d.push_back(point(x, y));
- }
- double rr;
- for (int i = 0; i < 3; i++)
- {
- rr = dist(a, d[i]);
- rr = sqrt(rr * rr - r * r);
- point c1, c2;
- cross(a, rr, d[i], r, c1, c2);
- bool f = true;
- for (int j = 0; j < 3; j++)
- {
- if (crossring(line(a, c1), d[j]) == 2)
- {
- f = false;
- break;
- }
- }
- if (f)
- {
- g[a].push_back(make_pair(dist(a, c1), c1));
- //cout << c1.x << " " << c1.y << endl;
- g[c1].push_back(make_pair(dist(a, c1), a));
- }
- f = true;
- for (int j = 0; j < 3; j++)
- {
- if (crossring(line(a, c2), d[j]) == 2)
- {
- f = false;
- break;
- }
- }
- if (f)
- {
- g[a].push_back(make_pair(dist(a, c2), c2));
- //cout << c2.x << " " << c2.y << endl;
- g[c2].push_back(make_pair(dist(a, c2), a));
- }
- double ll = r * acos(1 - dist(c1, c2) * dist(c1, c2) / (2 * r * r));
- g[c1].push_back(make_pair(ll, c2));
- g[c2].push_back(make_pair(ll, c1));
- }
- for (int i = 0; i < 3; i++)
- {
- rr = dist(b, d[i]);
- rr = sqrt(rr * rr - r * r);
- point c1, c2;
- cross(b, rr, d[i], r, c1, c2);
- bool f = true;
- for (int j = 0; j < 3; j++)
- {
- if (crossring(line(b, c1), d[j]) == 2)
- {
- f = false;
- break;
- }
- }
- if (f)
- {
- g[b].push_back(make_pair(dist(b, c1), c1));
- //cout << c1.x << " " << c1.y << endl;
- g[c1].push_back(make_pair(dist(b, c1), b));
- }
- f = true;
- for (int j = 0; j < 3; j++)
- {
- if (crossring(line(b, c2), d[j]) == 2)
- {
- f = false;
- break;
- }
- }
- if (f)
- {
- g[b].push_back(make_pair(dist(b, c2), c2));
- //cout << c2.x << " " << c2.y << endl;
- g[c2].push_back(make_pair(dist(b, c2), b));
- }
- double ll = r * acos(1 - dist(c1, c2) * dist(c1, c2) / (2 * r * r));
- g[c1].push_back(make_pair(ll, c2));
- g[c2].push_back(make_pair(ll, c1));
- }
- for (int i = 0; i < 2; i++)
- for (int j = i + 1; j < 3; j++)
- {
- point o1 = d[i], o2 = d[j];
- point v = o2 - o1;
- v = v / 2;
- point c1, c2, c3, c4;
- double rr = sqrt(dist(v, o1) * dist(v, o1) - r * r);
- cross(v, rr, o1, r, c[0], c[1]);
- cross(v, rr, o2, r, c[2], c[3]);
- /*c[0] = c1;
- c[1] = c2;
- c[2] = c3;
- c[3] = c4;*/
- for (int l = 0; l < 3; l++)
- {
- for (int k = l + 1; k < 4; k++)
- {
- bool f = true;
- for (int h = 0; h < 3; h++)
- {
- if (crossring(line(c[l], c[k]), d[j]) == 2)
- {
- f = false;
- break;
- }
- }
- if (f)
- {
- g[c[l]].push_back(make_pair(dist(c[l], c[k]), c[k]));
- //cout << c1.x << " " << c1.y << endl;
- g[c[k]].push_back(make_pair(dist(c[l], c[k]), c[l]));
- }
- }
- }
- double ll = r * acos(1 - dist(c[0], c[1]) * dist(c[0], c[1]) / (2 * r * r));
- g[c[0]].push_back(make_pair(ll, c[1]));
- g[c[1]].push_back(make_pair(ll, c[0]));
- ll = r * acos(1 - dist(c[2], c[3]) * dist(c[2], c[3]) / (2 * r * r));
- g[c[2]].push_back(make_pair(ll, c[3]));
- g[c[3]].push_back(make_pair(ll, c[2]));
- }
- for (int i = 0; i < 2; i++)
- for (int j = i + 1; j < 3; j++)
- {
- point o1 = d[i], o2 = d[j];
- point c1, c2, c3, c4;
- parkas(o1, o2, c[0], c[1], c[2], c[3]);
- /*c[0] = c1;
- c[1] = c2;
- c[2] = c3;
- c[3] = c4;*/
- for (int l = 0; l < 3; l++)
- {
- for (int k = l + 1; k < 4; k++)
- {
- bool f = true;
- for (int h = 0; h < 3; h++)
- {
- if (crossring(line(c[l], c[k]), d[j]) == 2)
- {
- f = false;
- break;
- }
- }
- if (f)
- {
- g[c[l]].push_back(make_pair(dist(c[l], c[k]), c[k]));
- //cout << c1.x << " " << c1.y << endl;
- g[c[k]].push_back(make_pair(dist(c[l], c[k]), c[l]));
- }
- }
- }
- double ll = r * acos(1 - dist(c[0], c[1]) * dist(c[0], c[1]) / (2 * r * r));
- g[c[0]].push_back(make_pair(ll, c[1]));
- g[c[1]].push_back(make_pair(ll, c[0]));
- ll = r * acos(1 - dist(c[2], c[3]) * dist(c[2], c[3]) / (2 * r * r));
- g[c[2]].push_back(make_pair(ll, c[3]));
- g[c[3]].push_back(make_pair(ll, c[2]));
- }
- bool f = true;
- for (int i = 0; i < 3; i++)
- {
- if (crossring(line(a, b), d[i]) == 2)
- {
- f = false;
- break;
- }
- }
- if (f)
- {
- g[a].push_back(make_pair(dist(a, b), b));
- //cout << c1.x << " " << c1.y << endl;
- g[b].push_back(make_pair(dist(a, b),a));
- }
- cout << g.size() << endl;
- for(map < point, vector < pair < double, point > > >::iterator ii = g.begin(); ii != g.end(); ii++)
- {
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement