• uva 12296


    发现自己对pslg这边不怎么会,打算对着蓝书刷几道康康
    不过好像近几年确实很冷门虽然牛客多校出了个板子

    这个就是简单的cut多边形然后暴力判就行了

    这macOS 10.15到底有啥用啊,测试版就有clion不能debug的问题了,正式版竟然还有。。。
    去jb看他们好像说在clion 9月17那个版本里把这个问题解决了?但是我下了一遍没用?
    唔雨又下大了((
    唔ummmm>_<

    #include <bits/stdc++.h>
    #define pii pair<int,int>
    #define yxn inline
    #define INF 19970404
    using namespace std;
    typedef double db;
    const db eps=1e-6;
    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;}
    db Area(vector<point> A){ // 多边形用 vector<point> 表示 , 逆时针
        db ans=0;
        for (int i=0;i<A.size();i++) ans+=cross(A[i],A[(i+1)%A.size()]);
        return ans/2;
    }
    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;}
        line(){}
        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(){ // 向外 ( 左手边 ) 平移 eps
            const db eps = 1e-6;
            point delta=(p[1]-p[0]).turn90().unit()*eps;
            return {p[0]-delta,p[1]-delta};
        }
    };
    point getLL(line k1,line k2){return getLL(k1[0],k1[1],k2[0],k2[1]);}
    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};
    }
    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;
    }
    vector<point> convexcut(vector<point>A,point k1,point k2){//多边形
        // 保留 k1,k2,p 逆时针的所有点
        int n=A.size(); A.push_back(A[0]); vector<point>ans;
        for (int i=0;i<n;i++){
            int w1=clockwise(k1,k2,A[i]),w2=clockwise(k1,k2,A[i+1]);
            if (w1>=0) ans.push_back(A[i]);
            if (w1*w2<0) ans.push_back(getLL(k1,k2,A[i],A[i+1]));
        }
        return ans;
    }
    //---------板子分界线--------------------------------
    int n,m,L,W;
    circle c;
    vector<line>l;
    vector<vector<point>>ply,nply;
    vector<point> v;
    
    bool check(vector<point> v){
        if(c.inside(v[0])==1)return true;
        if(contain(v,c.o)>=1)return true;
        //if(c.inside(v[0]))return true;
        for(int i=0;i<v.size();i++){
            vector<point> x = getCL(c,v[i],v[(i+1)%v.size()]);//
    //        for(auto p:x)if(onS(v[i],v[(i+1)%n],p)&&!(p==v[i])&&!(p==v[(i+1)%n]))return true;
            if(cmp(disSP(v[i],v[(i+1)%v.size()],c.o),c.r)==-1){
                return true;
            }
        }
        return false;
    }
    void slove(){
        vector<db> ans;
        for(int i=0;i<ply.size();i++){
            if(check(ply[i])){
                //printf("%d
    ",i);
                ans.push_back(abs(Area(ply[i])));
            }
        }
        sort(ans.begin(),ans.end());
        printf("%d",(int)ans.size());
        for(auto x:ans){
            printf(" %.2f",x);
        }
        printf("
    ");
    }
    void cut(line l){
        nply.clear();
        for(int i=0;i<ply.size();i++){
            vector<point> x = convexcut(ply[i],l[0],l[1]);
            vector<point> y = convexcut(ply[i],l[1],l[0]);
            if(x.size()>=3)nply.push_back(x);
            if(y.size()>=3)nply.push_back(y);
        }
        ply=nply;
    }
    int main(){
        while(scanf("%d%d%d%d", &n, &m, &L, &W) == 4 && n) {
            v.clear();ply.clear();nply.clear();
            v.push_back({0,0});
            v.push_back({1.0*L,0});
            v.push_back({1.0*L,1.0*W});
            v.push_back({0,1.0*W});
            ply.push_back(v);
            l.resize(n);
            for(int i=0;i<n;i++){
                scanf("%lf%lf%lf%lf",&l[i][0].x,&l[i][0].y,&l[i][1].x,&l[i][1].y);
                cut(l[i]);
    //            printf("%d
    ",(int)ply.size());
            }
            for(int i=0;i<m;i++){
                scanf("%lf%lf%lf",&c.o.x,&c.o.y,&c.r);
                slove();
            }
            printf("
    ");
        }
    }
    
  • 相关阅读:
    TCP和UDP协议?
    了解浏览器缓存机制吗?
    关于预检请求?
    cookie可设置哪些属性?httponly?
    http和https?
    vue自定义组件?
    实现页面回退刷新?
    vue3.0的更新和defineProperty优化?
    vue的seo问题?
    vuex组成和原理?
  • 原文地址:https://www.cnblogs.com/MXang/p/11644908.html
Copyright © 2020-2023  润新知