You went to an exciting adventure in a deep jungle but sadly a giant captured you. The giant said th…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
t = int(input())
for i in range(0,t):
a,b,c=map(int,input().split())
s = (a+b+c)/2
area =(s * (s-a) * (s-b) * (s-c))**(1/2)
if a+b>=c and b+c>=a and c+a>=b:
print("%.2f"%area)
else:
print("Oh, No!")
this doesn’t create triangle. IT’S A STRAIGHT LINE. DO THEY KNOW MATH ?
a = int(input())
b = int(input())
c = int(input())
if (a+b) > c and (a+c) > b and (b+c) > a:
s = (a + b + c) / 2
area = (s*(s-a)(s-b)(s-c))**0.5
print(“{0:.2f}”.format(float(area)))
else:
print(“Oh, No!”)
The test cases are WRONG for this problem!
I think, problem setter forgot that (a+b >= c && a+c >= b && c+a >= b) DOESN’T form a triangle. It must be (a+b > c && a+c > b && c+a > b) for a triangle.
Cause your logic ain’t right, just try to learn the conditions that makes a triangle.
Just having sides > 0 does not form a triangle.
For example, can you form a triangle with sides with length 7, 2 and 12 ?
try it yourself and then rethink the logic.
@ProgrammarSk use <= instead of <here. 0 is also considered as a valid result here.
cause it satisfies the equation area = sqrt(s(s-a)(s-b)(s-c))
and also i wonder how you code is even compiling?
you have to put asterisk * whereever you perform multiplication in a c/c++ program.
so you have to write:
I think the test case 2 should be updated. Because we know sum of two sides of a triangle must be greater than the third side. I submitted my code with this theory but I got wrong answer. But when I submitted my code with the wrong theory I got AC.
The wrong theory:
a+b>=c
a+c>=b
b+c>=a
Anything that returns positive real number in the equation s = root(s * (s - a) * (s - b) * (s - c)) has been considered the sides of a correct triangle for this problem.