洛谷 P2571 [SCOI2010]传送带 题解

每日一题 day51 打卡

Analysis

这道题是用非常恶心的三分套三分做的,有一个技巧是不要枚举坐标,枚举两条线段构成三角形的相似比就好了。

了解思路就还挺好写的(尽管我还调了三天)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 #define int long long
 7 #define rep(i,s,e) for(register int i=s;i<=e;++i)
 8 #define dwn(i,s,e) for(register int i=s;i>=e;--i)
 9 using namespace std;
10 inline int read()
11 {
12     int x=0,f=1;
13     char c=getchar();
14     while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();}
15     while(c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();}
16     return f*x;
17 }
18 inline void write(int x)
19 {
20     if(x<0) {putchar('-'); x=-x;}
21     if(x>9) write(x/10);
22     putchar(x%10+'0'); 
23 }
24 struct node
25 {
26     double x,y;
27 }a,b,c,d;
28 double p,q,r;
29 inline node calc_point(node a,node b,double k)
30 {
31     node point;
32     point.x=(b.x-a.x)*k+a.x;
33     point.y=(b.y-a.y)*k+a.y;
34     return point;
35 }
36 inline double calc_dis(node a,node b)
37 {
38     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
39 }
40 inline double check_two(double k1,double k2)
41 {
42     node point_one=calc_point(a,b,k1),point_two=calc_point(c,d,k2);
43     double dis1=calc_dis(a,point_one)/p,dis2=calc_dis(point_one,point_two)/r,dis3=calc_dis(point_two,d)/q;
44     return dis1+dis2+dis3;
45 }
46 inline double check_one(double k)
47 {
48     double l2=0.0,r2=1.0;
49     while(r2-l2>1e-9)
50     {
51         double mid12=l2+(r2-l2)/3.0,mid22=r2-(r2-l2)/3.0;
52         if(check_two(k,mid12)>check_two(k,mid22)) l2=mid12;
53         else r2=mid22;
54     }
55     return check_two(k,l2);
56 }
57 signed main()
58 {
59     scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
60     scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
61     scanf("%lf%lf%lf",&p,&q,&r);
62     double l1=0.0,r1=1.0;
63     while(r1-l1>1e-9)
64     {
65         double mid11=l1+(r1-l1)/3.0,mid21=r1-(r1-l1)/3.0;
66         if(check_one(mid11)>check_one(mid21)) l1=mid11;
67         else r1=mid21;
68     }
69     printf("%.2lf",check_one(l1));
70     return 0;
71 }

请各位大佬斧正(反正我不认识斧正是什么意思)

原文地址:https://www.cnblogs.com/handsome-zyc/p/11961303.html