Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Triangle
- {
- static void Main()
- {
- int aX = int.Parse(Console.ReadLine());
- int aY = int.Parse(Console.ReadLine());
- int bX = int.Parse(Console.ReadLine());
- int bY = int.Parse(Console.ReadLine());
- int cX = int.Parse(Console.ReadLine());
- int cY = int.Parse(Console.ReadLine());
- double lineA = calculateLine(bX, aX, bY, aY);
- double lineB = calculateLine(cX, bX, cY, bY);
- double lineC = calculateLine(cX, aX, cY, aY);
- if (isTriangle(lineA,lineB,lineC))
- {
- Console.WriteLine("Yes");
- double p = (lineA + lineB + lineC) / 2;
- double area = p * (p - lineA) * (p - lineB) * (p - lineC);
- area = GetSquareRoot(area, 0, area);
- Console.WriteLine("{0:f2}",area);
- }
- else
- {
- Console.WriteLine("No");
- Console.WriteLine("{0:f2}",calculateLine(aX,bX,aY,bY));
- }
- }
- static double calculateLine(int x2, int x1, int y2, int y1)
- {
- double lineToSqrt = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
- lineToSqrt = GetSquareRoot(lineToSqrt, 0, lineToSqrt);
- return lineToSqrt;
- }
- static bool isTriangle(double a, double b, double c)
- {
- bool isTriangle = a + b > c && b + c > a && a + c > b;
- return isTriangle;
- }
- public static double GetSquareRoot(double n, double low, double high)
- {
- double errorMargin = 0.001;
- double sqrt = (low + high) / 2;
- double diff = sqrt * sqrt - n;
- if (diff > errorMargin)
- return GetSquareRoot(n, low, sqrt);
- if (-diff > errorMargin)
- return GetSquareRoot(n, sqrt, high);
- return sqrt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement