• P2521 [HAOI2011]防线修建


    传送门

    一眼看出可以倒着做转为加点维护凸包,然后……然后我就不会了……

    看了一眼题解,大概是这样的,我们先把所有点都读进来,然后按极角排序,也就是说定义点的大小为他们极角的大小(本题里实际上直接按x坐标和y坐标排序也没事,代码里就这样写的)

    那么我们可以把所有凸包上的点都给扔进一个set里,每次插入一个点的时候找到它的前驱和后继,然后用叉积计算它到那两个点的夹角是凹的还是凸的,如果是凸的那么这个点就要加入凸包。然后再往两边继续搜,把所有不应该在凸包里的点给删掉

    因为每个点只会被删一次,所以插入是均摊(O(logn))

    然后就是调代码的时候一些比较玄学的事情……一直WA然后调了半天……最后发现几个变量定义的顺序换了一下就可以了?这有什么不对的么我不是很明白诶?

    算了……这一个小时就当在划水好了……

    //minamoto
    #include<bits/stdc++.h>
    #define IT set<node>::iterator
    #define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
    #define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
    using namespace std;
    #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    char buf[1<<21],*p1=buf,*p2=buf;
    int read(){
        int res,f=1;char ch;
        while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
        for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
        return res*f;
    }
    const int N=5e5+5;
    struct node{
    	int x,y;
    	node(int X=0,int Y=0):x(X),y(Y){}
    }p[N];set<node>A;
    int n,x,y,m,q,tot;bool vis[N];double now;
    struct qqq{int op,i;}op[N];double ans[N];
    inline node operator -(node a,node b){return node(a.x-b.x,a.y-b.y);}
    inline double operator *(node a,node b){return a.x*b.y-b.x*a.y;}
    inline bool operator <(node a,node b){return a.x==b.x?a.y>b.y:a.x<b.x;}
    inline double dis(node a,node b){return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
    void ins(node x){
        IT r=A.lower_bound(x),l=r,t;--l;
        if((*l-x)*(*r-x)<0)return;
        now-=dis(*l,*r);
        while(r!=A.end()){
            t=r,++r;
            if((*r-x)*(*t-x)>0)break;
            now-=dis(*t,*r),A.erase(t);
        }
        while(l!=A.begin()){
            t=l,--l;
            if((*t-x)*(*l-x)>0)break;
            now-=dis(*t,*l),A.erase(t);
        }A.insert(x),l=r=t=A.find(x),--l,++r;
        now+=dis(*l,x)+dis(*r,x);
    }
    int main(){
    //	freopen("testdata.in","r",stdin);
        n=read(),x=read(),y=read(),m=read();
        fp(i,1,m)p[i].x=read(),p[i].y=read();
        q=read();fp(i,1,q){
            op[i].op=read();
            if(op[i].op==1)op[i].i=read(),vis[op[i].i]=true;
        }
        now+=dis(node(0,0),node(x,y)),now+=dis(node(x,y),node(n,0));
        A.insert(node(0,0)),A.insert(node(n,0)),A.insert(node(x,y));
        fp(i,1,m)if(!vis[i])ins(p[i]);
        fd(i,q,1)if(op[i].op==1)ins(p[op[i].i]);
        else ans[++tot]=now;
        fd(i,tot,1)printf("%.2lf
    ",ans[i]);return 0;
    }
    
  • 相关阅读:
    关于1961年4月16日尤文图斯91国际米兰的故事
    《转》struts2动态方法配置 Action,使一个Action可处理多请求
    struts2跳转后总是会返回input
    CentOS设置服务开机自动启动【转】
    CentOS 6.2系统安装后的初始环境设置
    Ubuntu安装小技巧 拔掉网线
    虚拟机最小安装CentOS 6.2
    CentOS 6.2配置MySQL服务器
    CentOS修改机器名称
    配置GNOME环境
  • 原文地址:https://www.cnblogs.com/bztMinamoto/p/10009281.html
Copyright © 2020-2023  润新知