Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include <string>
- #include <stdio.h>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <math.h>
- #include <cmath>
- #include <queue>
- #include <iomanip>
- #include <bitset>
- #include <unordered_map>
- #include <stack>
- #include <memory.h>
- #include <list>
- #include <unordered_set>
- #include <complex>
- #include <cassert>
- #include <numeric>
- #include <functional>
- #define ll long long
- #define ld long double
- #define ull unsigned ll
- #define mp make_pair
- #define all(x) (x).begin(),(x).end()
- #define rall(x) (x).rbegin(),(x).rend()
- #define pii pair<int,int>
- #define vi vector<int>
- #define vpii vector<pii>
- #define vvi vector<vector<int>>
- #define endl '\n'
- #define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
- const ll Inf = 1e18;
- ll LINF = (ll)2e18;
- using namespace std;
- ll mod = 1e9 + 7;
- ll mod3 = 998244353;
- ll mod2 = 1e9 + 123;
- #define M_PI 3.14159265358979323846 // pi
- struct pt {
- ld x, y;
- };
- ld get_dist(const pt &p1, const pt &p2) {
- return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
- }
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- //freopen("javacert.in", "r", stdin);
- //freopen("javacert.out", "w", stdout);
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif
- ios::sync_with_stdio(false);
- cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(5);
- ld x1, y1, x2, y2;
- int n;
- cin >> x1 >> y1 >> x2 >> y2 >> n;
- ld k = (y2 - y1) / (x2 - x1);
- ld ans = 0;
- forn(i, 0, n) {
- ld x0, y0, r;
- cin >> x0 >> y0 >> r;
- //cout << x0 << " " << y0 << " " << r << endl;
- ld cc = x1 * k - y1 + y0;
- ld a = k * k + 1;
- ld b = -2.0 * cc*k - 2.0 * x0;
- ld c = cc * cc + x0 * x0 - r * r;
- cout << a << " " << b << " " << c << endl;
- ld d = b * b - 4.0 * a*c;
- if (d > 0) {
- ld x_1 = (-b - sqrt(d)) / (2.0 * a);
- ld x_2 = (-b + sqrt(d)) / (2.0 * a);
- ld y_1 = k * x_1 - x1 * k + y1;
- ld y_2 = k * x_2 - x1 * k + y1;
- if (x1 > x2) swap(x1, x2);
- if (y1 > y2) swap(y1, y2);
- if (x_1<x1 || x_1>x2 || x_2<x1 || x_2>x2) continue;
- ans += get_dist({ x_1, y_1 }, { x_2, y_2 });
- }
- }
- //cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement