ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 2148. Безумный выстрел

AC C++ tangent and vectors
Послано D4nick 18 сен 2020 21:17
M - middle between Sher and the aim, S - required point, O - the center of the tank, X, Y - projection of some line on x or y.
First "if" means that the distance between Sher and the aim is less then length of a tangent inside the circle.
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    double xc, yc, x1, y1, x2, y2, r, xm, ym, xs, ys, MO, MS, Xmo, Ymo, Xms, Yms;
    cin >> xc >> yc >> r >>
        x1 >> y1 >>
        x2 >> y2;
        if (4 * (pow(x1 - xc, 2) + pow(y1 - yc, 2) - pow(r, 2)) <= pow(x2 - x1, 2) + pow(y2 - y1, 2)) {
            cout << "No way";
            return 0;
        }
        xm = (x1 + x2) / 2; ym = (y1 + y2) / 2;
        MO = sqrt(pow(xm - xc, 2) + pow(ym - yc, 2));
        MS = MO - r;
        Xmo = xc - xm; Ymo = yc - ym;
        Xms = MS*Xmo / MO; Yms = MS*Ymo / MO;
        xs = xm + Xms; ys = ym + Yms;
        cout.precision(6);
        cout.setf(ios::fixed);
        cout << xs << ' ' << ys;
}

Edited by author 18.09.2020 21:19