Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <iomanip>
- #include <algorithm>
- #include <cmath>
- #include <cassert>
- using namespace std;
- typedef long double T;
- const T EPS = 1e-9;
- struct Point {
- Point(T x_, T y_) : x(x_), y(y_) {}
- Point() {}
- Point& operator=(const Point& p) {
- x = p.x;
- y = p.y;
- return *this;
- }
- T x;
- T y;
- };
- Point operator+ (const Point& p1, const Point& p2) {
- return Point(p1.x + p2.x, p1.y + p2.y);
- }
- Point operator- (const Point& p1, const Point& p2) {
- return Point(p1.x - p2.x, p1.y - p2.y);
- }
- T operator^ (const Point& p1, const Point& p2) {
- return p1.x * p2.x + p1.y * p2.y;
- }
- T operator* (const Point& p1, const Point& p2) {
- return p1.x * p2.y - p1.y * p2.x;
- }
- Point operator*(const Point& p1, T c) {
- return Point(p1.x * c, p1.y * c);
- }
- Point operator*(T c, const Point& p1) {
- return Point(p1.x * c, p1.y * c);
- }
- bool isZero(T x) {
- return fabsl(x) < EPS;
- }
- bool areEqual(T x, T y) {
- return isZero(x - y);
- }
- bool isLessThan(T x, T y) {
- return (x - y) < (-1 * EPS);
- }
- bool isMoreThan(T x, T y) {
- return (x - y) > EPS;
- }
- bool isNoLessThan(T x, T y) {
- return !isLessThan(x, y);
- }
- bool isNoMoreThan(T x, T y) {
- return !isMoreThan(x, y);
- }
- T len2(const Point& p) {
- return p.x * p.x + p.y * p.y;
- }
- bool areEqual(const Point& p1, const Point& p2) {
- return areEqual(p1.x, p2.x) && areEqual(p1.y, p2.y);
- }
- bool areCollinear(const Point& p1, const Point& p2) {
- return isZero(p1 * p2);
- }
- bool areCodirected(const Point& p1, const Point& p2) {
- return areCollinear(p1, p2) && isNoLessThan(p1 ^ p2, 0);
- }
- bool isOnLine(const Point& a, const Point& b, const Point& c) {
- return areCollinear(b - a, c - a);
- }
- bool isOnSegment(const Point& a, const Point& b, const Point& c) {
- return areCodirected(a - b, c - a);
- }
- Point findLinesIntersection(const Point& a, const Point& b, const Point& c, const Point& d) {
- T t = ((c - a) * (d - c)) / ((b - a) * (d - c));
- return a + (t * (b - a));
- }
- int main() {
- cout << setprecision(20);
- long double x0;
- int w = 0;
- while (cin >> x0) {
- if (w != 0) {
- cout << endl;
- }
- w++;
- long double y0, r, x1, y1, x2, y2;
- cin >> y0 >> r >> x1 >> y1 >> x2 >> y2;
- auto a = Point(x0, y0);
- auto b = Point(x1, y1);
- auto c = Point(x2, y2);
- b = b - a;
- c = c - a;
- if (r == 0) {
- if ((x1 == x2) && (y1 == y2)) {
- if ((x1 == x0) && (y1 == y0)) {
- cout << 1 << endl;
- cout << x0 << " " << y0 << endl;
- } else {
- cout << 0 << endl;
- }
- } else {
- if (isOnSegment(Point(0, 0), b, c)) {
- cout << 1 << endl;
- cout << x0 << " " << y0 << endl;
- } else {
- cout << 0 << endl;
- }
- }
- continue;
- }
- if (x1 == x2 && y1 == y2) {
- if (areEqual(len2(b), r * r)) {
- cout << 1 << endl;
- cout << x1 << " " << y1 << endl;
- } else {
- cout << 0 << endl;
- }
- continue;
- }
- /////////////////
- Point a1 = b - c;
- Point b1 = c;
- long double desc = (a1 ^ b1) * (a1 ^ b1) - (a1 ^ a1) * ((b1 ^ b1) - r * r);
- if (desc < -EPS) {
- cout << 0 << endl;
- } else if (areEqual(desc, 0)) {
- long double t = (-1) * (a1 ^ b1) / (a1 ^ a1);
- Point ans = b * t + (1 - t) * c;
- if (((0 - EPS) <= t) && (t <= 1 + EPS)) {
- cout << 1 << endl;
- cout << (ans.x + a.x) << " " << (ans.y + a.y) << endl;
- } else {
- cout << 0 << endl;
- }
- } else {
- long double t1 = (((-1) * (a1 ^ b1)) + sqrtl(desc)) / (a1 ^ a1);
- long double t2 = (((-1) * (a1 ^ b1)) - sqrtl(desc)) / (a1 ^ a1);
- Point ans1 = b * t1 + (1 - t1) * c;
- Point ans2 = b * t2 + (1 - t2) * c;
- if (len2(ans1 - ans2) <= EPS) {
- cout << 1 << endl;
- cout << ans1.x + a.x << " " << ans1.y + a.y << endl;
- continue;
- }
- if (((0 - EPS) <= t1) && (t1 <= 1 + EPS)) {
- if (((0 - EPS) <= t2) && (t2 <= 1 + EPS)) {
- bool ord = ans1.x == ans2.x ? ans1.y < ans2.y : ans1.x < ans2.x;
- if (ord) {
- cout << 2 << endl;
- cout << (ans1.x + a.x) << " " << (ans1.y + a.y) << endl;
- cout << (ans2.x + a.x) << " " << (ans2.y + a.y) << endl;
- } else {
- cout << 2 << endl;
- cout << (ans2.x + a.x) << " " << (ans2.y + a.y) << endl;
- cout << (ans1.x + a.x) << " " << (ans1.y + a.y) << endl;
- }
- } else {
- cout << 1 << endl;
- cout << (ans1.x + a.x) << " " << (ans1.y + a.y) << endl;
- }
- } else {
- if (((0 - EPS) <= t2) && (t2 <= 1 + EPS)) {
- cout << 1 << endl;
- cout << (ans2.x + a.x) << " " << (ans2.y + a.y) << endl;
- } else {
- cout << 0 << endl;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement