• 【HDOJ】3400 Line belt


    三分。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 
     5 typedef struct {
     6     double x, y;
     7 } Point_t;
     8 
     9 Point_t A, B, C, D;
    10 const double eps = 1.0e-8;
    11 double P, Q, R;
    12 
    13 double dist(Point_t a, Point_t b) {
    14     return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
    15 }
    16 
    17 double t_ab(Point_t a, Point_t b) {
    18     return dist(a, b)/P;
    19 }
    20 
    21 double t_cd(Point_t c, Point_t d) {
    22     return dist(c, d)/Q;
    23 }
    24 
    25 double t_oth(Point_t x, Point_t y) {
    26     return dist(x, y)/R;
    27 }
    28 
    29 double tri_cd(Point_t c, Point_t d, Point_t S) {
    30     Point_t left = c, right = d;
    31     Point_t p1, p2;
    32 
    33     while (dist(left, right) > eps) {
    34         p1.x = left.x*2.0/3.0 + right.x/3.0;
    35         p1.y = left.y*2.0/3.0 + right.y/3.0;
    36         p2.x = left.x/3.0 + right.x*2.0/3.0;
    37         p2.y = left.y/3.0 + right.y*2.0/3.0;
    38         if (t_oth(S, p1)+t_cd(p1, D) <= t_oth(S, p2)+t_cd(p2, D)) {
    39             right = p2;
    40         } else {
    41             left = p1;
    42         }
    43     }
    44     return t_oth(S, left) + t_cd(left, d);
    45 }
    46 
    47 double tri_ab(Point_t a, Point_t b) {
    48     Point_t left = a, right = b;
    49     Point_t p1, p2;
    50 
    51     while (dist(left, right) > eps) {
    52         p1.x = left.x*2.0/3.0 + right.x/3.0;
    53         p1.y = left.y*2.0/3.0 + right.y/3.0;
    54         p2.x = left.x/3.0 + right.x*2.0/3.0;
    55         p2.y = left.y/3.0 + right.y*2.0/3.0;
    56         if (t_ab(a, p1)+tri_cd(C, D, p1) <= t_ab(a, p2)+tri_cd(C, D, p2)) {
    57             right = p2;
    58         } else {
    59             left = p1;
    60         }
    61     }
    62     return t_ab(a, left) + tri_cd(C, D, left);
    63 }
    64 
    65 int main() {
    66     int t;
    67 
    68     scanf("%d", &t);
    69     while (t--) {
    70         scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);
    71         scanf("%lf%lf%lf%lf",&C.x,&C.y,&D.x,&D.y);
    72         scanf("%lf%lf%lf", &P, &Q, &R);
    73         printf("%.2lf
    ", tri_ab(A, B));
    74     }
    75 
    76     return 0;
    77 }
  • 相关阅读:
    mybatis中的配置文件的约束
    win10下PHP开发环境搭建
    装饰器的理解
    在iis上添加woff字体文件读取
    转发:使用sql命令查询视图中所有引用的基础表
    转:C4项目中验证用户登录一个特性就搞定
    转载:NSobject官方介绍
    thinkphp生命周期
    array_intersect_assoc — 带索引检查计算数组的交集
    array_flip — 交换数组中的键和值
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3979732.html
Copyright © 2020-2023  润新知