ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1348. Goat in the Garden 2

My solution (RUS/ENG) (Accepted)
Posted by Vladislav_Kucherenko 25 May 2024 21:16
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
int x1, y1, x2, y2, x0, y0, l;

cin >> x1 >> y1 >> x2 >> y2;
cin >> x0 >> y0 >> l;
cout << fixed << setprecision(2); // <|ENG: Set 2 symbols after dot |> <|RUS: stavim 2 simvola dlia tochki |>
//<|ENG: get all sides |>
//<|RUS: poluchaem vse storonui |>
double firstEdge = sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2));
double secondEdge = sqrt(pow(x2 - x0, 2) + pow(y2 - y0, 2));
double field = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
double ans2 = max(firstEdge, secondEdge) - l; // <|ENG: Second answer - max length |> <|RUS: Vtoroi otvet = prosto maximum do krainih tochek |>

double ans1;
//<|ENG: get the squares of the sides|>
//<|RUS: Vosvodim v kvadrat storonui |>
double a = firstEdge * firstEdge;
double b = secondEdge * secondEdge;
double c = field * field;
//<|ENG: checking if there are obtuse angles on the side that is the pineapple field |>
//<|RUS: Proverka est li typie ygli vosle toi storoni kotoraiy iavliaetsia polem c ananasami |>
if (a+c < b || b+c < a) {
ans1 = min(firstEdge, secondEdge) - l;
}
else {
//<|ENG: get half the perimeter of triangle|>
//<|RUS: poluchaem poly perimetr treygolnika |>
double p = (firstEdge + secondEdge + field) / 2;
//<|ENG: get square of triangle|>
double S = sqrt(p * (p - firstEdge) * (p - secondEdge) * (p - field));

//<|ENG: If the area is zero and the field with pineapples does not exist (test: 2 2 2 2 3 3 1)|>
//<|RUS: Esli ploshad ravna 0 i polia c ananasami kak bu net (test: 2 2 2 2 3 3 1)|>
if (S == 0 && field == 0) {
ans1 = min(firstEdge, secondEdge) - l;
}
//<|ENG: If the area is zero and more than one side is not zero (test: -5 0 5 0 1 0 1)|>
//<|RUS: Esli ploshad ravna 0 i ni odna storona ne ravna 0 (test:  -5 0 5 0 1 0 1)|>
else if (S == 0 && firstEdge != 0 && secondEdge != 0 && field != 0) {
ans1 =  0;
}
else {
//<|ENG: Default. We just look for the height using the formula|>
//<|RUS: Obichni slychai. Prosto po formule S = a*h/2 (test:  -5 0 5 0 1 0 1)|>
double d = 2 * S / field;
ans1 = d - l;
}
}
//<|ENG: If, after subtracting the rope, the length becomes negative, then do 0|>
//<|RUS: Esli sle vichetania verevki otvet stal menihe nylia to delayem 0|>
ans1 = ans1 < 0 ? 0 : ans1;
ans2 = ans2 < 0 ? 0 : ans2;

//<|ENG: Next just cout "round(ans1 * 100) / 100" and "round(ans2 * 100) / 100"|>
//<|RUS: Teper prosto vivedi "round(ans1 * 100) / 100" i "round(ans2 * 100) / 100"|>

//!!!!!!!!!!!!!!!!!!!
//cout << round(ans1 * 100) / 100 << endl;
//cout << round(ans2 * 100) / 100;
return 0;

//<|ENG: Thanks a lot for your time here!|>
//<|RUS: Spasibo chto pochitali i uia vam pomog (navernoe)|>
// :)
}