hdu 5476 Explore Track of Point(2015上海网络赛)

  题目链接:hdu 5476

  今天和队友们搞出3道水题后就一直卡在这儿了,唉,真惨啊……看着被一名一名地挤出晋级名次,确实很不好受,这道恶心的几何题被我们3个搞了3、4个小时,我想到一半时发现样例输出是 (√2) π / 2 + 1, 于是就各种 YY,无奈尝试了各种方法还是免不了 wa。。。

  后来在网上发现,那段圆弧其实就和自己插身而过,真的可以说差一点就想到了,无奈到了最后我们几个都精疲力尽了,好像也想不出什么了。看下图:

   就是三角形里的圆弧的长度,设为 Lc ,很容易得出 Lc = | OC | * 2 * ∠O,而 ∠O = ∠ACM,∠ACM可以由 | AM | 与 | CM | 的 atan 值求出,而 | OC | = | CM | / sin(∠O),所以,核心代码就几行而已:  

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 
 7 struct point {
 8     double x,y;
 9     point() {}
10     point(double x, double y): x(x), y(y) {}
11     void read()  {   scanf("%lf %lf",&x,&y);   }
12     void readint() {
13         int x,y;
14         scanf("%d %d",&x,&y);
15         this->x = x;
16         this->y = y;
17     }
18     point operator + (const point &p2) const {
19         return point(x + p2.x, y + p2.y);
20     }
21     point operator - (const point &p2) const {
22         return point(x - p2.x, y - p2.y);
23     }
24     point operator * (double p) const {
25         return point(x * p, y * p);
26     }
27     point operator / (double p) const {
28         return point(x / p, y / p);
29     }
30 };
31 
32 typedef point Vector;
33 typedef const point& cpoint;
34 typedef const Vector& cvector;
35 
36 point operator * (double p, Vector a) {
37     return a * p;
38 }
39 
40 double dot(cvector a, cvector b) {
41     return a.x * b.x + a.y * b.y;
42 }
43 
44 double length(cvector a) {
45     return sqrt(dot(a,a));
46 }
47 
48 double angle(cvector a, cvector b) {
49     return acos(dot(a,b) / length(a) / length(b));
50 }
51 
52 double cross(cvector a, cvector b) {
53     return a.x * b.y - a.y * b.x;
54 }
55 
56 const double PI = acos(-1.0);
57 
58 int main() {
59     int t, Case = 0;
60     point a,b,c;
61     scanf("%d",&t);
62     while(t--) {
63         a.readint();
64         b.readint();
65         c.readint();
66         point m = (b + c) / 2;
67         double am = length(m - a), cm = length(m - c);
68         double angO = atan(am / cm);
69         double oc = cm / sin(angO);
70         double ans = oc * 2 * angO + am;
71         printf("Case #%d: %.4f\n",++Case,ans);
72     }
73     return 0;
74 }
View Code

  附上证明截图:(刚刚看懂,好强大~~ Orz Orz)

posted @ 2015-09-26 21:15  Newdawn_ALM  阅读(302)  评论(0编辑  收藏  举报