Advertisement
nq1s788

Untitled

Nov 29th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <iomanip>
  5. #define x first
  6. #define y second
  7.  
  8. using namespace std;
  9.  
  10. pair<int, int> input() {
  11.     int x, y;
  12.     cin >> x >> y;
  13.     return make_pair(x, y);
  14. }
  15.  
  16. pair<int, int> summ(pair<int, int> a, pair<int, int> b) {
  17.     return make_pair(a.x + b.x, a.y + b.y);
  18. }
  19.  
  20. pair<int, int> razn(pair<int, int> a, pair<int, int> b) {
  21.     return make_pair(a.x - b.x, a.y - b.y);
  22. }
  23.  
  24. int cross(pair<int, int> a, pair<int, int> b) {
  25.     return a.x * b.y - a.y * b.x;
  26. }
  27.  
  28. int scalar(pair<int, int> a, pair<int, int> b) {
  29.     return a.x * b.x + a.y * b.y;
  30. }
  31.  
  32. double len(pair<int, int> a, pair<int, int> b) {
  33.     pair<int, int> n;
  34.     n = make_pair(abs(a.x - b.x), abs(a.y - b.y));
  35.     return sqrt(scalar(n, n));
  36. }
  37.  
  38. pair<int, int> vect(pair<int, int> a, pair<int, int> b) {
  39.     return make_pair(b.x - a.x, b.y - a.y);
  40. }
  41.  
  42. int main() {
  43.     pair<int, int> a, b, c, zero;
  44.     double H;
  45.     zero = make_pair(0, 0);
  46.     a = input();
  47.     b = input();
  48.     c = input();
  49.     int l;
  50.     cin >> l;
  51.     cout << fixed << setprecision(2);
  52.     double A = len(a, c);
  53.     double B = len(b, c);
  54.     if(a == b){
  55.         H = A;
  56.     } else {
  57.         H = abs(cross(vect(c, a), vect(c, b)) / len(a, b));
  58.     }
  59.     if(A <= B) {
  60.         double k = scalar(vect(a, b), vect(a, c));
  61.         cout << (k < 0? max(A - l, 0.0) : max(H - l, 0.0)) << endl;
  62.     } else {
  63.         double k = scalar(vect(b, a), vect(b, c));
  64.         cout << (k < 0? max(B - l, 0.0) : max(H - l, 0.0)) << endl;
  65.     }
  66.     cout << max({A - l, B - l, 0.0});
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement