码迷,mamicode.com
首页 > 其他好文 > 详细

HDU3400 三分套三分

时间:2018-11-18 22:39:30      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:struct   速度   iostream   一个人   pac   cond   style   ios   second   

题意

就是给你两条线段AB , CD ,一个人在AB以速度p跑,在CD上以q跑,

在其他地方跑速度是r。问你从A到D最少的时间。

 

三分AB ,然后再三分CD ,模板题目,这题卡精度 eps不能少

 

技术分享图片
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <queue>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <set>
 7 #include <iostream>
 8 #include <map>
 9 #include <stack>
10 #include <string>
11 #include <vector>
12 #define  pi acos(-1.0)
13 #define  eps 1e-9
14 #define  fi first
15 #define  se second
16 #define  rtl   rt<<1
17 #define  rtr   rt<<1|1
18 #define  bug         printf("******\n")
19 #define  mem(a,b)    memset(a,b,sizeof(a))
20 #define  name2str(x) #x
21 #define  fuck(x)     cout<<#x" = "<<x<<endl
22 #define  f(a)        a*a
23 #define  sf(n)       scanf("%d", &n)
24 #define  sff(a,b)    scanf("%d %d", &a, &b)
25 #define  sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
26 #define  sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
27 #define  pf          printf
28 #define  FRE(i,a,b)  for(i = a; i <= b; i++)
29 #define  FREE(i,a,b) for(i = a; i >= b; i--)
30 #define  FRL(i,a,b)  for(i = a; i < b; i++)+
31 #define  FRLL(i,a,b) for(i = a; i > b; i--)
32 #define  FIN         freopen("data.txt","r",stdin)
33 #define  gcd(a,b)    __gcd(a,b)
34 #define  lowbit(x)   x&-x
35 using namespace std;
36 typedef long long  LL;
37 typedef unsigned long long ULL;
38 const int mod = 1e9 + 7;
39 const int maxn = 2e5 + 10;
40 const int INF = 0x3f3f3f3f;
41 const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
42 int t;
43 double P, Q, R, len1, len2;
44 struct node {
45     double x, y;
46 } a, b, c, d, temp1, temp2;
47 double dist ( node a, node b ) {
48     return sqrt ( eps + ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) );
49 }
50 void caltemp1 ( double cnt ) {
51     temp1.x = a.x + ( b.x - a.x ) / len1 * cnt;
52     temp1.y = a.y + ( b.y - a.y ) / len1 * cnt;
53 }
54 void caltemp2 ( double cnt ) {
55     temp2.x = d.x + ( c.x - d.x ) / len2 * cnt;
56     temp2.y = d.y + ( c.y - d.y ) / len2 * cnt;
57 }
58 double check ( double cnt ) {
59     caltemp1 ( cnt );
60     double l = 0, r = len2, ll, rr, ans1, ans2;
61     while ( r - l > eps ) {
62         ll = ( 2 * l + r ) / 3, rr = ( 2 * r + l ) / 3;
63         caltemp2 ( ll );
64         ans1 = dist ( temp1, temp2 ) / R + dist ( d, temp2 ) / Q;
65         caltemp2 ( rr );
66         ans2 = dist ( temp1, temp2 ) / R + dist ( d, temp2 ) / Q;
67         if ( ans1 < ans2 ) r = rr;
68         else l = ll;
69     }
70     return ans1 + dist ( temp1, a ) / P;
71 }
72 int main()  {
73     scanf ( "%d", &t );
74     while ( t-- ) {
75         scanf ( "%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y );
76         scanf ( "%lf%lf%lf%lf", &c.x, &c.y, &d.x, &d.y );
77         scanf ( "%lf%lf%lf", &P, &Q, &R );
78         len1 = dist ( a, b ), len2 = dist ( c, d );
79         double l = 0, r = len1, ll, rr;
80         while ( r - l > eps ) {
81             ll = ( 2 * l + r ) / 3, rr = ( 2 * r + l ) / 3;
82             if ( check ( ll ) < check ( rr ) ) r = rr;
83             else l = ll;
84         }
85         printf ( "%.2f\n", check ( ll ) );
86     }
87     return 0;
88 }
View Code

 

HDU3400 三分套三分

标签:struct   速度   iostream   一个人   pac   cond   style   ios   second   

原文地址:https://www.cnblogs.com/qldabiaoge/p/9979604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!