Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <stdio.h>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <math.h>
  10. #include <cmath>
  11. #include <queue>
  12. #include <iomanip>
  13. #include <bitset>
  14. #include <unordered_map>
  15. #include <stack>
  16. #include <memory.h>
  17. #include <list>
  18. #include <unordered_set>
  19. #include <complex>
  20. #include <cassert>
  21. #include <numeric>
  22. #include <functional>
  23.  
  24. #define ll long long
  25. #define ld long double
  26. #define ull unsigned ll
  27. #define mp make_pair
  28. #define all(x) (x).begin(),(x).end()
  29. #define rall(x) (x).rbegin(),(x).rend()
  30. #define pii pair<int,int>
  31. #define vi vector<int>
  32. #define vpii vector<pii>
  33. #define vvi vector<vector<int>>
  34. #define endl '\n'
  35. #define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
  36. const ll  Inf = 1e18;
  37. ll LINF = (ll)2e18;
  38. using namespace std;
  39. ll mod = 1e9 + 7;
  40. ll mod3 = 998244353;
  41. ll mod2 = 1e9 + 123;
  42. #define M_PI       3.14159265358979323846   // pi
  43.  
  44. struct pt {
  45.     ld  x, y;
  46. };
  47.  
  48. ld get_dist(const pt &p1, const pt &p2) {
  49.     return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
  50. }
  51.  
  52. int main() {
  53. #ifdef _DEBUG
  54.     freopen("input.txt", "r", stdin);
  55.     freopen("output.txt", "w", stdout);
  56. #else
  57.     //freopen("javacert.in", "r", stdin);
  58.     //freopen("javacert.out", "w", stdout);
  59.     //freopen("input.txt", "r", stdin);
  60.     //freopen("output.txt", "w", stdout);
  61. #endif
  62.     ios::sync_with_stdio(false);
  63.     cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(5);
  64.     ld x1, y1, x2, y2;
  65.     int n;
  66.     cin >> x1 >> y1 >> x2 >> y2 >> n;
  67.     ld k = (y2 - y1) / (x2 - x1);
  68.     ld ans = 0;
  69.     forn(i, 0, n) {
  70.         ld x0, y0, r;
  71.         cin >> x0 >> y0 >> r;
  72.         //cout << x0 << " " << y0 << " " << r << endl;
  73.         ld cc = x1 * k - y1 + y0;
  74.         ld a = k * k + 1;
  75.         ld b = -2.0 * cc*k - 2.0 * x0;
  76.         ld c = cc * cc + x0 * x0 - r * r;
  77.         cout << a << " " << b << " " << c << endl;
  78.         ld d = b * b - 4.0 * a*c;
  79.         if (d > 0) {
  80.             ld x_1 = (-b - sqrt(d)) / (2.0 * a);
  81.             ld x_2 = (-b + sqrt(d)) / (2.0 * a);
  82.             ld y_1 = k * x_1 - x1 * k + y1;
  83.             ld y_2 = k * x_2 - x1 * k + y1;
  84.             if (x1 > x2) swap(x1, x2);
  85.             if (y1 > y2) swap(y1, y2);
  86.             if (x_1<x1 || x_1>x2 || x_2<x1 || x_2>x2) continue;
  87.             ans += get_dist({ x_1, y_1 }, { x_2, y_2 });
  88.         }
  89.     }
  90.     //cout << ans;
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement