zoukankan      html  css  js  c++  java
  • uva 11796

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #define eps 1e-8
    #define max(a,b) a>b?a:b
    
    using namespace std;
    
    int sig(double a)
    {
        return (a>eps)-(a<-eps);
    }
    
    typedef struct point
    {
        double x,y;
        point(double xx=0,double yy=0):x(xx),y(yy){}
    }vector;
    
    vector operator - (point a,point b)
    {
        return vector(a.x-b.x,a.y-b.y);
    }
    point operator + (point a,vector b)
    {
        return point(a.x+b.x,a.y+b.y);
    }
    vector operator * (vector a,double b)
    {
        return vector(a.x*b,a.y*b);
    }
    double dot(vector a,vector b)
    {
        return a.x*b.x+a.y*b.y;
    }
    double len(vector a)
    {
        return sqrt(dot(a,a));
    }
    double cross(vector a,vector b)
    {
        return a.x*b.y-a.y*b.x;
    }
    vector resiz(vector a,double l)
    {
        l/=len(a);
        return vector(a.x*l,a.y*l);
    }
    double dis(point p,point a,vector v)
    {
        point b=a+v;
        vector v1=p-a,v2=p-b;
        if(sig(dot(v,v1))<=0) return len(v1);
        else if(sig(dot(v,v2))>=0) return len(v2);
        return fabs(cross(v1,v))/len(v);
    }
    
    int main()
    {
        int i,j,m,n,t,c=0;
        double mx,mn,v1,v2,l1,l2,d;
        point p[51],q[51],a,b;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&m,&n);
            v1=v2=0;
            for(i=0;i<m;i++)
            {
                scanf("%lf%lf",&p[i].x,&p[i].y);
                if(i) v1+=len(p[i]-p[i-1]);
            }
            for(i=0;i<n;i++)
            {
                scanf("%lf%lf",&q[i].x,&q[i].y);
                if(i) v2+=len(q[i]-q[i-1]);
            }
            mn=mx=len(p[0]-q[0]);
            a=p[0];b=q[0];
            for(i=1,j=1;i<m;)
            {
                l1=len(p[i]-a);l2=len(q[j]-b);
                d=l1/v1-l2/v2;
                if(sig(d)>0)
                {
                    vector w=resiz(p[i]-a,l2*v1/v2),u=w-(q[j]-b);
                    d=dis(b,a,u);
                    if(sig(mn-d)>0) mn=d;
                    d=max(len(b-a),len(b-a-u));
                    if(sig(mx-d)<0) mx=d;
                    a=a+w;b=q[j++];
                }
                else if(sig(d)<0)
                {
                    vector w=resiz(q[j]-b,l1*v2/v1),u=w-(p[i]-a);
                    d=dis(a,b,u);
                    if(sig(mn-d)>0) mn=d;
                    d=max(len(b-a),len(a-b-u));
                    if(sig(mx-d)<0) mx=d;
                    b=b+w;a=p[i++];
                }
                else
                {
                    vector u=(q[j]-b)-(p[i]-a);
                    d=dis(a,b,u);
                    if(sig(mn-d)>0) mn=d;
                    d=max(len(b-a),len(a-b-u));
                    if(sig(mx-d)<0) mx=d;
                    a=p[i++];b=q[j++];
                }
            }
            printf("Case %d: %.lf
    ",++c,mx-mn);
        }
        return 0;
    }
    


  • 相关阅读:
    新浪微博 js 解密
    新浪微博、qq rsa密码加密c#实现
    C#版本的discuz authcode函数
    搬地方了,在github弄了个新博客
    python 发送邮件
    通用网页广告监测,ADBlock plus算法的C#实现。
    58同城登录 c#,非直接操作js
    python模块之smtplib: 用python发送SSL/TLS安全邮件
    Python少打字小技巧
    python模块之poplib: 用pop3收取邮件
  • 原文地址:https://www.cnblogs.com/pangblog/p/3285536.html
Copyright © 2011-2022 走看看