acdream.18.KIDx's Triangle(数学推导)

KIDx's Triangle

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

One day, KIDx solved a math problem for middle students in seconds! And than he created this problem.

Now, give you the degree of a, b, c, d, please calculate the degree of ∠AED.

Input

There are multiple test cases.

Each case contains one line 4 integers formatted as: "a b c d"

0 ≤ a, b, c, d < 90°.

0 < a+b < 90°, 0 < c+d < 90°.

Output

For each test case, output the answer in one line, rounded to 2 decimal places.

Sample Input

10 70 60 20
10 70 70 0

Sample Output

20.00
140.00
 1 #include<stdio.h>
 2 #include<math.h>
 3 #define pi 3.141592653589793
 4 double a , b , c , d ;
 5 double BE , BD , DE , bata , AD , AE ;
 6 
 7 inline double f (double k)
 8 {
 9     return 1.0 * k * pi / 180 ;
10 }
11 
12 int main ()
13 {
14     freopen ("a.txt" , "r" , stdin ) ;
15     while (~ scanf ("%lf%lf%lf%lf" , &a , &b , &c , &d)) {
16         if (a == 0) {
17             printf ("0.00
") ;
18             continue ;
19         }
20         AD = sin (f(c)) / sin (f(a + b + c)) ;
21         BD = sin (f(c + d)) / sin (f(a + b + c + d)) - sin (f(c)) / sin (f(a + b + c)) ;
22         BE = sin (f(a + b)) / sin (f(a + b + c + d)) - sin (f(b)) / sin (f(b + c + d)) ;
23 
24         DE = sqrt (1.0 * (BE * BE + BD * BD + 2 * BE * BD * cos (f(a + b + c + d)))) ;
25         AE = sin (f(c + d)) / sin (f(b + c + d)) ;
26         bata =  acos (1.0 * (DE * DE + AE * AE - AD * AD) / (2.0 * DE * AE)) * 180 / pi;
27             //    printf ("DE = %.2f , EF = %.2f , DF = %.2f
" , DE , EF , DF) ;
28      //   printf ("bata = %.2f
" , bata * 180 / pi) ;
29         if (bata < 0)
30             printf ("%.2f
" ,180.0 - bata) ;
31         else
32             printf ("%.2f
" , bata) ;
33     }
34     return 0 ;
35 }
View Code

标程中的大写字母表示角度,小写字母表示边长,注意0的特殊情况即可

设CE = a = 1,AE = b,AC = c,BE = d,AB = e,AD = f,BD = g,DE = h

使用正弦定理可依次求出AE,AB,AD

然后利用余弦定理依次求出DE,∠AED

其他解法:建立坐标系搞,或者二分搞

原文地址:https://www.cnblogs.com/get-an-AC-everyday/p/4417602.html