简体   繁体   English

直角三角形可能吗?

[英]Is a right angle triangle possible?

Given h , the hypotenuse and s , the surface area, it is asked to print the sides of the right angle triangle if possible, else print -1 . 给定h为斜边, s为表面积,如果可能,要求打印直角三角形的边,否则打印-1 So here was my approach; 所以这就是我的方法;

   double h,s;
   scanf("%lf %lf",&h,&s);
   s*=4;
   double squaresum=(h*h) + s;
   double squarediff=(h*h) - s;
   if(squarediff<0)
       printf("-1\n");
   else
   {
       double a = sqrt(squaresum)+sqrt(squarediff);
       a/=2;
       double b = sqrt(squaresum)-sqrt(squarediff);
       b/=2;
       if(h>=a+b)
            printf("-1\n");
       else
        printf("%.6lf %.6lf %.6lf\n",h,a,b);
   }

My approach: 我的方法:
Given s , if we multiply 4 , then it is 2*a*b , where a and b are the other sides of the triangle. 给定s ,如果我们乘以4 ,则它为2*a*b ,其中ab是三角形的另一边。 Then I find (a+b)^2 and (ab)^2 as I have h*h=a^2+b^2 . 然后我发现(a+b)^2(ab)^2因为我有h*h=a^2+b^2 It even passed the custom test case: 它甚至通过了自定义测试用例:

4
5 6
6 10
258303 89837245228
616153 77878145466

Output: 输出:

4.000000 3.000000 5.000000
-1
-1
546189.769984 285168.817674 616153.000000

But the answer is being judged as wrong. 但是答案被认为是错误的。 I am not able to pick up how the answer could go wrong given 0<=h<=10^9 and 0<=s<=10^12 . 0<=h<=10^90<=s<=10^12我无法理解答案可能会出错。 The problem link- 问题链接
https://www.codechef.com/problems/RIGHTTRI https://www.codechef.com/problems/RIGHTTRI

Maybe I'm wrong, but if I read the Output required : 也许我错了,但是如果我阅读了必需的输出:

Output the answer for each test-case in a single line. 在一行中输出每个测试用例的答案。 If it is not possible to find such a triangle, output -1. 如果找不到这样的三角形,则输出-1。 Otherwise print 3 real numbers corresponding to the lengths of the sides of the triangle sorted in non-decreasing order . 否则,打印3个实数,该实数对应于以非降序排序的三角形边的长度。 Please note that the length of the triangle sides should not differ by more than 0.01 in absolute value from the correct lengths. 请注意,三角形边的长度与正确长度的绝对值相差不得超过0.01。

Your output is not sorted... I guess non-decreasing order means increasing order... Maybe give it a shot before anything else... 您的输出未排序...我想不降序意味着升序...也许比其他任何事情都要先尝试一下...

(Edited question according to comment) : (根据评论编辑的问题):

non-decreasing order means you must sort them number from the lowest to the highest, by length : 不降序排列意味着您必须按照长度从低到高对它们进行排序:

3.000000 4.000000 5.000000 3.000000 4.000000 5.000000

Mainly the issue with math problems is to understand what they want from you... 数学问题主要是要了解他们想要从您那里得到什么...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM