• 18上海大都会赛G


    卡epssm
    先判是不是个凸包,
    显然我们要旋转点,
    显然在一定范围内是有单调性的,
    这个范围不太好找,我们把2pi分成若干小段,其中这些小段里有单调性,最后取min就行,eps太大会wa,推荐1e-11.
    注意check的时候不能是『那样的形状』自己脑补去吧

    #include <bits/stdc++.h>
    using namespace std;
    typedef double db;
    const db eps=1e-11;
    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);}
    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);}
    };
    db cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}
    vector<point> ConvexHull(vector<point>A,int flag=1){ // flag=0 不严格 flag=1 严格
        int n=A.size(); vector<point>ans(n*2);
        sort(A.begin(),A.end()); int now=-1;
        for (int i=0;i<A.size();i++){
            while (now>0&&sign(cross(ans[now]-ans[now-1],A[i]-ans[now-1]))<flag) now--;
            ans[++now]=A[i];
        } int pre=now;
        for (int i=n-2;i>=0;i--){
            while (now>pre&&sign(cross(ans[now]-ans[now-1],A[i]-ans[now-1]))<flag) now--;
            ans[++now]=A[i];
        } ans.resize(now); return ans;
    }
    int t;
    vector<point> p,s;
    db check(db x){
        for(int i=0;i<4;i++)
            s[i]=p[i].turn(x);
        db mnx=1e404,mxx=-1e404,mny=1e404,mxy=-1e404;
        int mxxid,mxyid,mnyid,mnxid;
        for(int i=0;i<4;i++){
            if (s[i].x < mnx)mnx = s[i].x, mnxid = i;
            if (s[i].x > mxx)mxx = s[i].x, mxxid = i;
            if (s[i].y < mny)mny = s[i].y, mnyid = i;
            if (s[i].y > mxy)mxy = s[i].y, mxyid = i;
        }
        if (mnxid == mnyid || mnxid == mxyid)return 11111;
        if (mxxid == mxyid || mxxid == mnyid)return 11111;
        return fabs(mxy-mny-(mxx-mnx));
    }
    db slove(db l,db r){//三回啊三回
        while (l+eps<=r){
            db lm = l+(r-l)/3;
            db rm = r-(r-l)/3;
            if(check(lm)>=check(rm))l=lm;
            else r=rm;
        }
        return check(l);
    }
    int main(){
        scanf("%d",&t);int cas=0;
        while (t--){
            p.resize(4);
            s.resize(4);
            for(int i=0;i<4;i++){
                scanf("%lf%lf",&p[i].x,&p[i].y);
            }
            p=ConvexHull(p);
            if(p.size()!=4){
                printf("Case %d: No
    ",++cas);
                continue;
            }
            db s = 1e18;
            for(db i=0;i<2*pi;i+=pi/3){
                s = min(s,slove(i,i+pi/3));
            }
            if(s<=1e-8)printf("Case %d: Yes
    ",++cas);
            else printf("Case %d: No
    ",++cas);
        }
    }
    
    

    可能这就是我单身的原因吧。
    最近几天情绪大概会很失落。

  • 相关阅读:
    小实例 hangman game
    二分搜索
    基于xml的aop开发
    Discuz! 6.x/7.x 全局变量防御绕过导致命令执行
    PHP执行linux系统命令
    IP反查网站,ip反查接口,旁站查询接口大全,通过IP查域名汇总:
    取消sudo的密码
    linux之kali系统ssh服务开启
    Linux下自动备份MySQL数据库详细操作步骤(转载)
    MongoDB学习笔记(一) MongoDB介绍及安装
  • 原文地址:https://www.cnblogs.com/MXang/p/11582106.html
Copyright © 2020-2023  润新知