zoj3525掃描線

來源:互聯網
上載者:User

題目大意:
給你一個長方體,讓你求這個長方體可以圈住的點的最小權值和;
思路:
首先枚舉x座標,找出區間長度不超過la的區間;
然後限定y座標,當其區間長度在所給範圍內則加上相應數值,若超過了則減去相應數值。
最後限定z座標,使得更新的區間長度恰好等於所給的範圍;

#include<bits/stdc++.h>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;const int maxn=1009;const int N=5009;int mx[N<<2],tag[N<<2];int la,lb,lc;struct node{    int x,y,z,v;} num[maxn];int cmp1(node a,node b){    return a.x<b.x;}struct line{    int x,l,r,v;    line(int a,int b,int c,int d)    {        x=a,l=b,r=c,v=d;    }};int cmp2(line a,line b){    if(a.x!=b.x)        return a.x<b.x;    return a.v>b.v;}int pushup(int rt){    mx[rt]=max(mx[rt<<1],mx[rt<<1|1]);}int pushdown(int rt){    if(tag[rt])    {        tag[rt<<1]+=tag[rt];        tag[rt<<1|1]+=tag[rt];        mx[rt<<1]+=tag[rt];        mx[rt<<1|1]+=tag[rt];        tag[rt]=0;    }}void build(int l,int r,int rt){    tag[rt]=0;    mx[rt]=0;    if(l<r)    {        int m=l+r>>1;        build(lson);        build(rson);    }}void update(int L,int R,int v,int l,int r,int rt){    if(L<=l&&r<=R)    {        tag[rt]+=v;        mx[rt]+=v;        return;    }    pushdown(rt);    int m=l+r>>1;    if(L<=m)        update(L,R,v,lson);    if(m<R)        update(L,R,v,rson);    pushup(rt);}int cal(int a,int b){    vector<line> t;    for(int i=a; i<=b; i++)    {        int tx=num[i].y,ty=num[i].z,tz=num[i].v;        t.push_back(line(tx,ty,ty+lc,tz));        t.push_back(line(tx+lb,ty,ty+lc,-tz));    }    sort(t.begin(),t.end(),cmp2);    build(0,N,1);    int mxm=-0x3f3f3f3f;    for(int i=0; i<t.size(); i++)    {        update(t[i].l,t[i].r,t[i].v,0,N,1);        mxm=max(mxm,mx[1]);    }    return mxm;}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int x,y,z,v;        int cnt=0;        for(int i=1; i<=n; i++)        {            scanf("%d%d%d%d",&x,&y,&z,&v);            if(v<0)            {                num[cnt].x=x+1000;                num[cnt].y=y+1000;                num[cnt].z=z+1000;                num[cnt++].v=-v;            }        }        scanf("%d%d%d",&la,&lb,&lc);        if(cnt==0)        {            puts("Error 404, mahou shoujo not found!");            continue;        }        sort(num,num+cnt,cmp1);        int mm=0;        for(int i=0,j=0; i<cnt&&j<cnt;)        {            while(j<cnt&&num[j].x-num[i].x<=la) j++;            mm=max(mm,cal(i,j-1));            while(i+1<cnt&&num[i+1].x==num[i].x) i++;            i++;        }        printf("%d\n",-mm);    }    return 0;}/*31 2 3 -91 6 7 -13 4 2 -42 2 4*/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.