Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(),(x).end()
- using namespace std;
- using ll = long long;
- struct pt {
- int x;
- int y;
- int ind;
- pt(int cx = 0, int cy = 0, int cind = 0) {
- this->x = cx;
- this->y = cy;
- this->ind = cind;
- }
- bool operator < (const pt& o) {
- return x < o.x || (x == o.x && y < o.y);
- }
- pt operator - (const pt& o) const {
- return pt(x - o.x, y - o.y);
- }
- };
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int ad, ac, bd, bc;
- cin >> ad >> ac >> bd >> bc;
- if (ad == bd && ac == bc) {
- cout << "Impossible." << endl;
- return 0;
- }
- auto get = [&] (double cosangle, int a, int b) {
- return sqrt(a * a + b * b - 2 * cosangle * a * b);
- };
- double k = ad * 1.0 / bc;
- double L1 = bd;
- double L2 = ac;
- /*
- * (L1 - x) / y == (L2 - y) / x == AD / BC
- * L1 - x = ky
- * L2 - y = kx
- * x = L1 - ky
- * L2 - y = k (L1 - ky)
- * L2 - y = kL1 - k**2 * y
- * (k**2 - 1) y = kL1 - L2
- * y = (kL1 - L2) / (k**2 - 1)
- * x = L1 - ky
- */
- if (abs(k * k - 1) < 1e-10) {
- cout << "Impossible.\n";
- return 0;
- }
- double y = (k * L1 - L2) / (k * k - 1);
- double x = L1 - k * y;
- double cosA = (x * x + bc * bc - y * y) / (2 * bc * x);
- cout << fixed << setprecision(0) << "Distance is " << get(cosA, ac, ad) * 1000 << " km." << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement