HDU 5858 Hard problem ——(计算几何)

  其实这题最多是个小学奥数题- -,,看到别人博客各显神通,也有用微积分做的(我也试了一下,结果到最后不会积。。。)。

  思路如下(这两张图是网上找来的):

  然后就很简单了,算三角形面积可以用海伦公式,也可以用1/2*a*b*sin(<a,b>)。代码如下:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include <math.h>
 5 using namespace std;
 6 typedef long long ll;
 7 
 8 double x;
 9 double pi = acos(-1.0);
10 
11 int main()
12 {
13     x = sqrt(7.0)/(4.0*sqrt(2.0));
14     int T;scanf("%d",&T);
15     while(T--)
16     {
17         double L;scanf("%lf",&L);
18         double d = 2 * x * L;
19         double th = 2.0 * asin(d/L);
20         double szong = pi * 0.25 * L * L * th / (2.0*pi);
21         double s1 = 0.5 * 0.25 * L * L * sin(th);
22         double th2 = 2.0 * asin(0.5*d/L);
23         double s2 = pi * L * L * th2 / (2.0*pi) - 0.5 * L * L * sin(th2);
24         double ans = szong - s1 - s2;
25         ans *= 2.0;
26         printf("%.2f
",ans);
27     }
28 }
原文地址:https://www.cnblogs.com/zzyDS/p/5792127.html