• hdu 6419


    哇太妙了啊
    我交了份一万多b的代码
    去看了下去年jls的录播,,,毕竟这怎么做啊。。。。 然后1A了。调试信息没删不能作数的
    其实很容易想到把边向里平移。。
    算了我还是直接复述叭,
    对每个点的圆,和所有平移R之后的线段,这两个集合求交点,也就是可行解。圆和圆,线段和线段也要求。
    然后对于每个询问,先check可行解。
    然后在分别check 每个圆和平移之后的线段即可。
    eps开大一点。。。(1e-2)
    只是单纯模拟的话板子没问题也很难出错叭

    #include <bits/stdc++.h>
    using namespace std;
    typedef double db;
    const db eps=1e-2;
    const db pi=acos(-1);
    int sign(db k){
        if (k>eps) return 1; else if (k<-eps) return -1; return 0;
    }
    int cmp(db k1,db k2){return sign(k1-k2);}
    int inmid(db k1,db k2,db k3){return sign(k1-k3)*sign(k2-k3)<=0;}// k3 在 [k1,k2] 内
    struct point{
        db x,y;
        point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
        point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
        point operator * (db k1) const{return (point){x*k1,y*k1};}
        point operator / (db k1) const{return (point){x/k1,y/k1};}
        int operator == (const point &k1) const{return cmp(x,k1.x)==0&&cmp(y,k1.y)==0;}
        // 逆时针旋转
        point turn(db k1){return (point){x*cos(k1)-y*sin(k1),x*sin(k1)+y*cos(k1)};}
        point turn90(){return (point){-y,x};}
        bool operator < (const point k1) const{
            int a=cmp(x,k1.x);
            if (a==-1) return 1; else if (a==1) return 0; else return cmp(y,k1.y)==-1;
        }
        db abs(){return sqrt(x*x+y*y);}
        db abs2(){return x*x+y*y;}
        db dis(point k1){return ((*this)-k1).abs();}
        point unit(){db w=abs(); return (point){x/w,y/w};}
        void scan(){double k1,k2; scanf("%lf%lf",&k1,&k2); x=k1; y=k2;}
        void print(){printf("%.11lf %.11lf
    ",x,y);}
        db getw(){return atan2(y,x);}
        point getdel(){if (sign(x)==-1||(sign(x)==0&&sign(y)==-1)) return (*this)*(-1); else return (*this);}
        int getP() const{return sign(y)==1||(sign(y)==0&&sign(x)==-1);}
    };
    int inmid(point k1,point k2,point k3){return inmid(k1.x,k2.x,k3.x)&&inmid(k1.y,k2.y,k3.y);}
    db cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}
    db dot(point k1,point k2){return k1.x*k2.x+k1.y*k2.y;}
    db rad(point k1,point k2){return atan2(cross(k1,k2),dot(k1,k2));}
    // -pi -> pi
    int compareangle (point k1,point k2){//极角排序+
        return k1.getP()<k2.getP()||(k1.getP()==k2.getP()&&sign(cross(k1,k2))>0);
    }
    point proj(point k1,point k2,point q){ // q 到直线 k1,k2 的投影
        point k=k2-k1;return k1+k*(dot(q-k1,k)/k.abs2());
    }
    point reflect(point k1,point k2,point q){return proj(k1,k2,q)*2-q;}
    int clockwise(point k1,point k2,point k3){// k1 k2 k3 逆时针 1 顺时针 -1 否则 0
        return sign(cross(k2-k1,k3-k1));
    }
    int checkLL(point k1,point k2,point k3,point k4){// 求直线 (L) 线段 (S)k1,k2 和 k3,k4 的交点
        return cmp(cross(k3-k1,k4-k1),cross(k3-k2,k4-k2))!=0;
    }
    point getLL(point k1,point k2,point k3,point k4){
        db w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3); return (k1*w2+k2*w1)/(w1+w2);
    }
    int intersect(db l1,db r1,db l2,db r2){
        if (l1>r1) swap(l1,r1); if (l2>r2) swap(l2,r2); return cmp(r1,l2)!=-1&&cmp(r2,l1)!=-1;
    }
    int checkSS(point k1,point k2,point k3,point k4){
        return intersect(k1.x,k2.x,k3.x,k4.x)&&intersect(k1.y,k2.y,k3.y,k4.y)&&
               sign(cross(k3-k1,k4-k1))*sign(cross(k3-k2,k4-k2))<=0&&
               sign(cross(k1-k3,k2-k3))*sign(cross(k1-k4,k2-k4))<=0;
    }
    db disSP(point k1,point k2,point q){
        point k3=proj(k1,k2,q);
        if (inmid(k1,k2,k3)) return q.dis(k3); else return min(q.dis(k1),q.dis(k2));
    }
    db disSS(point k1,point k2,point k3,point k4){
        if (checkSS(k1,k2,k3,k4)) return 0;
        else return min(min(disSP(k1,k2,k3),disSP(k1,k2,k4)),min(disSP(k3,k4,k1),disSP(k3,k4,k2)));
    }
    int onS(point k1,point k2,point q){return inmid(k1,k2,q)&&sign(cross(k1-q,k2-k1))==0;}
    struct circle{
        point o; db r;
        void scan(){o.scan(); scanf("%lf",&r);}
        int inside(point k){return cmp(r,o.dis(k));}
    };
    struct line{
        // p[0]->p[1]
        point p[2];
        line(point k1,point k2){p[0]=k1; p[1]=k2;}
        point& operator [] (int k){return p[k];}
        int include(point k){return sign(cross(p[1]-p[0],k-p[0]))>=0;}
        point dir(){return p[1]-p[0];}
        line push(db k){
            point delta=(p[1]-p[0]).turn90().unit()*k;
            return {p[0]+delta,p[1]+delta};
        }
    };
    point getLL(line k1,line k2){return getLL(k1[0],k1[1],k2[0],k2[1]);}
    int parallel(line k1,line k2){return sign(cross(k1.dir(),k2.dir()))==0;}
    int sameDir(line k1,line k2){return parallel(k1,k2)&&sign(dot(k1.dir(),k2.dir()))==1;}
    int operator < (line k1,line k2){
        if (sameDir(k1,k2)) return k2.include(k1[0]);
        return compareangle(k1.dir(),k2.dir());
    }
    int checkpos(line k1,line k2,line k3){return k3.include(getLL(k1,k2));}
    db closepoint(vector<point>&A,int l,int r){ // 最近点对 , 先要按照 x 坐标排序
        if (r-l<=5){
            db ans=1e20;
            for (int i=l;i<=r;i++) for (int j=i+1;j<=r;j++) ans=min(ans,A[i].dis(A[j]));
            return ans;
        }
        int mid=l+r>>1; db ans=min(closepoint(A,l,mid),closepoint(A,mid+1,r));
        vector<point>B; for (int i=l;i<=r;i++) if (abs(A[i].x-A[mid].x)<=ans) B.push_back(A[i]);
        sort(B.begin(),B.end(),[](point k1,point k2){return k1.y<k2.y;});
        for (int i=0;i<B.size();i++) for (int j=i+1;j<B.size()&&B[j].y-B[i].y<ans;j++) ans=min(ans,B[i].dis(B[j]));
        return ans;
    }
    int checkposCC(circle k1,circle k2){// 返回两个圆的公切线数量
        if (cmp(k1.r,k2.r)==-1) swap(k1,k2);
        db dis=k1.o.dis(k2.o);  int w1=cmp(dis,k1.r+k2.r),w2=cmp(dis,k1.r-k2.r);
        if (w1>0) return 4; else if (w1==0) return 3; else if (w2>0) return 2;
        else if (w2==0) return 1; else return 0;
    }
    vector<point> getCL(circle k1,point k2,point k3){ // 沿着 k2->k3 方向给出 , 相切给出两个
        point k=proj(k2,k3,k1.o); db d=k1.r*k1.r-(k-k1.o).abs2();
        if (sign(d)==-1) return {};
        point del=(k3-k2).unit()*sqrt(max((db)0.0,d)); return {k-del,k+del};
    }
    vector<point> getCC(circle k1,circle k2){// 沿圆 k1 逆时针给出 , 相切给出两个
        int pd=checkposCC(k1,k2); if (pd==0||pd==4) return {};
        db a=(k2.o-k1.o).abs2(),cosA=(k1.r*k1.r+a-k2.r*k2.r)/(2*k1.r*sqrt(max(a,(db)0.0)));
        db b=k1.r*cosA,c=sqrt(max((db)0.0,k1.r*k1.r-b*b));
        point k=(k2.o-k1.o).unit(),m=k1.o+k*b,del=k.turn90()*c;
        return {m-del,m+del};
    }
    vector<point> TangentCP(circle k1,point k2){// 沿圆 k1 逆时针给出
        db a=(k2-k1.o).abs(),b=k1.r*k1.r/a,c=sqrt(max((db)0.0,k1.r*k1.r-b*b));
        point k=(k2-k1.o).unit(),m=k1.o+k*b,del=k.turn90()*c;
        return {m-del,m+del};
    }
    vector<line> TangentoutCC(circle k1,circle k2){
        int pd=checkposCC(k1,k2); if (pd==0) return {};
        if (pd==1){point k=getCC(k1,k2)[0]; return {(line){k,k}};}
        if (cmp(k1.r,k2.r)==0){
            point del=(k2.o-k1.o).unit().turn90().getdel();
            return {(line){k1.o-del*k1.r,k2.o-del*k2.r},(line){k1.o+del*k1.r,k2.o+del*k2.r}};
        } else {
            point p=(k2.o*k1.r-k1.o*k2.r)/(k1.r-k2.r);
            vector<point>A=TangentCP(k1,p),B=TangentCP(k2,p);
            vector<line>ans; for (int i=0;i<A.size();i++) ans.push_back((line){A[i],B[i]});
            return ans;
        }
    }
    vector<line> TangentinCC(circle k1,circle k2){
        int pd=checkposCC(k1,k2); if (pd<=2) return {};
        if (pd==3){point k=getCC(k1,k2)[0]; return {(line){k,k}};}
        point p=(k2.o*k1.r+k1.o*k2.r)/(k1.r+k2.r);
        vector<point>A=TangentCP(k1,p),B=TangentCP(k2,p);
        vector<line>ans; for (int i=0;i<A.size();i++) ans.push_back((line){A[i],B[i]});
        return ans;
    }
    int contain(vector<point>A,point q){ // 2 内部 1 边界 0 外部
        int pd=0; A.push_back(A[0]);
        for (int i=1;i<A.size();i++){
            point u=A[i-1],v=A[i];
            if (onS(u,v,q)) return 1; if (cmp(u.y,v.y)>0) swap(u,v);
            if (cmp(u.y,q.y)>=0||cmp(v.y,q.y)<0) continue;
            if (sign(cross(u-v,q-v))<0) pd^=1;
        }
        return pd<<1;
    }
    int T;
    int n,m;db R;
    point a;
    vector<line> v,g;//线段
    bool check(point x){
        for(int i=0;i<n;i++){
            if(sign(disSP(v[i][0],v[i][1],x)-R)<0)
                return false;
        }
        return true;
    }
    circle c[222];
    vector<point> p,s,f;
    int main(){
        scanf("%d",&T);
        while (T--){
            v.clear();g.clear();p.clear();s.clear();f.clear();
            scanf("%d%d%lf",&n,&m,&R);
            p.resize(n);
            for(int i=0;i<n;i++){
                scanf("%lf%lf",&p[i].x,&p[i].y);
                c[i].o=p[i],c[i].r=R;
            }
            for(int i=0;i<n;i++){
                v.push_back(line(p[i],p[(i+1)%n]));//原多边形
                g.push_back(v[i].push(R));//移完
            }
            //求出来所有可行解
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                     if(checkLL(g[i][0],g[i][1],g[j][0],g[j][1])){
                         point x = getLL(g[i],g[j]);
                         if(g[i].include(x)&&g[j].include(x)&&contain(p,x)&&check(x)){
                             s.push_back(x);
                         }
                     }
                }
            }
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    f=getCC(c[i],c[j]);
                    for(auto x:f){
                        if(contain(p,x)&&check(x)){
                            s.push_back(x);
                        }
                    }
                }
            }
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    f=getCL(c[j],g[i][0],g[i][1]);
                    for(auto x:f){
                        if(g[i].include(x)&&contain(p,x)&&check(x)){
                            s.push_back(x);
                        }
                    }
                }
            }
    
    //        for(auto x:s){
    //            x.print();
    //        }
    
            //
            while (m--){
                scanf("%lf%lf",&a.x,&a.y);
                if(contain(p,a)&&check(a)){
                    printf("0
    ");
                    continue;
                }
                db ans = 1e9;
                for(auto x:s){
                    ans = min(ans,a.dis(x));
                }
                for(int i=0;i<n;i++){
                    point x = proj(g[i][0],g[i][1],a);
                    if(g[i].include(x)&&contain(p,x)&&check(x))
                        ans = min(ans,a.dis(x));
                }
                for(int i=0;i<n;i++){
                    f = getCL(c[i],c[i].o,a);
                    for(auto x:f){
                        if(contain(p,x)&&check(x)){
                            ans = min(ans,a.dis(x));
                        }
                    }
                }
                printf("%.0f
    ",ans);
            }
        }
    }
    
  • 相关阅读:
    Codeforces 231E
    Practice 15.07.07 计算几何
    Codeforces 552E
    Topcoder SRM 661 (Div.1) 250 MissingLCM
    HDU 4971
    Codeforces Round #306 (Div. 2)
    URAL 1988
    URAL 2032
    ServiceStack.Ormlit 事务
    ServiceStack.Ormlit 使用Insert的时候自增列不会被赋值
  • 原文地址:https://www.cnblogs.com/MXang/p/11296184.html
Copyright © 2020-2023  润新知