• poj3608 Bridge Across Islands


    23333我以前一定是学了假的旋转卡壳,,,,(以前只会面积的2333)

    换姿势,这个题用两条平行线搞,一共那么有一个点和一条线,两条线平行,这些个情况,那么就维护出这些东西就好了。

    (说的好简单啊2333)

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cmath>
     4 #define N 100005
     5 #define LL long long
     6 #define eps 1e-8
     7 using namespace std;
     8 inline int ra()
     9 {
    10     int x=0,f=1; char ch=getchar();
    11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    13     return x*f;
    14 }
    15 struct point
    16 {
    17     double x,y;
    18 }A[N],B[N];
    19 const double inf=1e50;
    20 int n,m;
    21 double cross(point c, point a, point b)
    22 {
    23     return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
    24 }
    25 double dot(point c, point a, point b)
    26 {
    27     return (a.x-c.x)*(b.x-c.x)+(a.y-c.y)*(b.y-c.y);
    28 }
    29 double dis(point a, point b)
    30 {
    31     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    32 }
    33 double point_line_dis(point a, point b, point aim)
    34 {
    35     if (dis(a,b)<eps) return dis(aim,a);
    36     if (dot(a,aim,b)<eps) return dis(aim,a);
    37     if (dot(b,aim,a)<eps) return dis(aim,b);
    38     return fabs(cross(aim,a,b))/dis(a,b);
    39 }
    40 double line_line_dis(point a, point b, point c, point d)
    41 {
    42     double dis1=min(point_line_dis(a,b,c),point_line_dis(a,b,d));
    43     double dis2=min(point_line_dis(c,d,a),point_line_dis(c,d,b));
    44     return min(dis1,dis2);
    45 }
    46 double RC(point *p, point *q, int n, int m)
    47 {
    48     p[n]=p[0]; q[m]=q[0];
    49     int down=0,up=0;
    50     for (int i=0; i<n; i++) if (p[i].y<p[down].y) down=i;
    51     for (int i=0; i<m; i++) if (q[i].y>q[up].y) up=i;
    52     double ans=inf;
    53     for (int i=0; i<n; i++)
    54     {
    55         double cnt;
    56         while (cnt=cross(p[down+1],q[up+1],p[down])-cross(p[down+1],q[up],p[down])>eps) up=(up+1)%m;
    57         if (cnt+eps<0) ans=min(ans,point_line_dis(p[down],p[down+1],q[up]));
    58             else ans=min(ans,line_line_dis(p[down],p[down+1],q[up],q[up+1]));
    59         down=(down+1)%n; 
    60     } 
    61     return ans;
    62 }
    63 int main(int argc, char const *argv[])
    64 {
    65     while (scanf("%d%d",&n,&m) && (n||m))
    66     {
    67         for (int i=0; i<n; i++) scanf("%lf%lf",&A[i].x,&A[i].y);
    68         for (int i=0; i<m; i++) scanf("%lf%lf",&B[i].x,&B[i].y);
    69         printf("%.5lf
    ",min(RC(A,B,n,m),RC(B,A,m,n)));
    70     }
    71     return 0;
    72 }
  • 相关阅读:
    Leetcode463. Island Perimeter
    C++ 编写的解码器小程序 map
    LeetCode706. Design HashMap
    LeetCode705. Design HashSet
    LeetCode804. Unique Morse Code Words
    c++后台开发 准备材料
    Scott Young-《如何高效学习》
    跳表和散列
    时间复杂度 log n
    第35题:LeetCode138. Copy List with Random Pointer
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6642140.html
Copyright © 2020-2023  润新知