Advertisement
Guest User

H

a guest
Sep 16th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.21 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. const long double inf = 2e18;
  9.  
  10. struct point {
  11.     long double x, y;
  12.  
  13.     long double len() {
  14.         return sqrt(x * x + y * y);
  15.     }
  16.  
  17.     void build(long double a, long double b) {
  18.         x = a;
  19.         y = b;
  20.     }
  21. };
  22.  
  23. struct line {
  24.     long double a, b, c, k, m;
  25.  
  26.     long double getY(long double x) {
  27.         if (b == 0) {
  28.             return inf;
  29.         }
  30.  
  31.         return -(c + a * x) / b;
  32.     }
  33.  
  34.     long double getX(long double y) {
  35.         if (a == 0) {
  36.             return inf;
  37.         }
  38.  
  39.         return -(c + b * y) / a;
  40.     }
  41.  
  42.     void buildPoints(point x, point y) {
  43.         a = x.y - y.y;
  44.         b = y.x - x.x;
  45.         c = x.x * y.y - y.x * x.y;
  46.  
  47.         if (b == 0) {
  48.             m = inf + x.x;
  49.             k = inf;
  50.         } else {
  51.             m = -c / b;
  52.             k = -a / b;
  53.         }
  54.     }
  55.  
  56.     void build(long double A, long double B, long double C) {
  57.         a = A;
  58.         b = B;
  59.         c = C;
  60.  
  61.         if (b == 0) {
  62.             m = inf;
  63.             k = inf;
  64.         } else {
  65.             m = -c / b;
  66.             k = -a / b;
  67.         }
  68.     }
  69.  
  70.     long double distance(point p) {
  71.         return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b);
  72.     }
  73. };
  74.  
  75. struct circle {
  76.     point center;
  77.     long double radius;
  78.  
  79.     pair<long double, long double> getY(long double x) {
  80.         pair<long double, long double> res = {inf, inf};
  81.         long double a = 1, b, c, d;
  82.         b = -2 * center.y;
  83.         c = center.y * center.y - radius * radius + (x - center.x) * (x - center.x);
  84.         d = b * b - 4.0 * a * c;
  85.  
  86.         if (d == 0) {
  87.             res.first = -b / 2.0;
  88.         }
  89.  
  90.         if (d > 0) {
  91.             res.first = (-b + sqrt(d)) / 2.0 / a;
  92.             res.first = (-b - sqrt(d)) / 2.0 / a;
  93.         }
  94.  
  95.         return res;
  96.     }
  97. };
  98.  
  99. point operator*(long double k, point a) {
  100.     point res;
  101.     res.x = a.x * k;
  102.     res.y = a.y * k;
  103.     return res;
  104. }
  105.  
  106. long double operator*(point a, point b) {
  107.     return a.x * b.x + a.y * b.y;
  108. }
  109.  
  110. long double operator^(point a, point b) {
  111.     return a.x * b.y - a.y * b.x;
  112. }
  113.  
  114. point operator-(point a, point b) {
  115.     point res;
  116.  
  117.     res.x = a.x - b.x;
  118.     res.y = a.y - b.y;
  119.  
  120.     return res;
  121. }
  122.  
  123. point operator+(point a, point b) {
  124.     point res;
  125.  
  126.     res.x = a.x + b.x;
  127.     res.y = a.y + b.y;
  128.  
  129.     return res;
  130. }
  131.  
  132. int main() {
  133.  
  134.     circle o;
  135.     line l;
  136.     point ans1, ans2, p;
  137.     long double x, y, z, D, a, b, c, d;
  138.  
  139.     scanf("%Lf %Lf %Lf %Lf %Lf %Lf", &o.center.x, &o.center.y, &o.radius, &x, &y, &z);
  140.  
  141.     l.build(x, y, z);
  142.  
  143.     a = l.a * l.a + l.b * l.b;
  144.     b = 2.0 * (l.a * l.c - o.center.x * l.b * l.b + l.a * l.b * o.center.y);
  145.     c = o.center.x * o.center.x * l.b * l.b + l.c * l.c + 2 * l.c * l.b * o.center.y + o.center.y * o.center.y * l.b * l.b - l.b * l.b * o.radius * o.radius;
  146.     d = b * b - 4.0 * a * c;
  147.  
  148.     if (l.distance(o.center) > o.radius) {
  149.         printf("0");
  150.     } else {
  151.         if (l.distance(o.center) == o.radius) {
  152.             ans1.x = -b / 2.0 / a;
  153.  
  154.             if (!l.b) {
  155.                 ans1.y = o.getY(ans1.x).first;
  156.             } else {
  157.                 ans1.y = l.getY(ans1.x);
  158.             }
  159.  
  160.             printf("1\n");
  161.             printf("%Lf %Lf", ans1.x, ans1.y);
  162.         } else {
  163.             ans1.x = (-b + sqrt(d)) / 2.0 / a;
  164.             ans2.x = (-b - sqrt(d)) / 2.0 / a;
  165.            
  166.             if (!l.b) {
  167.                 ans1.y = o.getY(ans1.x).first;
  168.                 ans2.y = o.getY(ans1.x).second;
  169.             } else {
  170.                 ans1.y = l.getY(ans1.x);
  171.                 ans2.y = l.getY(ans2.x);
  172.             }
  173.  
  174.             printf("2\n");
  175.             printf("%Lf %Lf\n", ans1.x, ans1.y);
  176.             printf("%Lf %Lf\n", ans2.x, ans2.y);
  177.         }
  178.     }
  179.  
  180.     return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement