设为首页 加入收藏

TOP

POJ线段树求矩形面积(三)
2012-12-06 13:48:29 来源: 作者: 【 】 浏览:838
Tags:POJ 线段 矩形 面积

 

    if(tt[pos].lp + 1 == tt[pos].rp)

    return;

    int mid = tt[pos].getmid();

    if(LL[id].lp >= mid){

    update(pos * 2 + 1,id);

    }

    else if(LL[id].rp <= mid){

    update(pos * 2,id);

    }

    else{

    update(pos * 2,id);

    update(pos * 2 + 1,id);

    }

    getlen(pos);

    }

    int main(){

    //freopen(“1.txt”,“r”,stdin);

    int a,b,c,d,tot = 0;

    while(scanf(“%d%d%d%d”,&a,&b,&c,&d) && (a + b + c + d) != -4){

    tot = 0;

    LL[tot].lp = a; LL[tot].rp = c; LL[tot].value = d; LL[tot++].cnt = 1;

    LL[tot].lp = a; LL[tot].rp = c; LL[tot].value = b; LL[tot++].cnt = -1;

    int x1,y1,x2,y2;

    while(1){

    scanf(“%d%d%d%d”,&x1,&y1,&x2,&y2);

    if(x1 + y1 + x2 + y2 == -4)

    break;

    LL[tot].lp = x1; LL[tot].rp = x2; LL[tot].value = y2; LL[tot++].cnt = 1;

    LL[tot].lp = x1; LL[tot].rp = x2; LL[tot].value = y1; LL[tot++].cnt = -1;

    }

    built_tree(0,N,1);

    sort(LL,LL+tot,cmp);

    update(1,0);

    long long ans = 0;

    for(int i = 1; i < tot; ++i){

    ans += tt .len * (LL[i-1].value - LL[i].value);

    update(1,i);

    }

    printf(“%lld\n”,ans);

    }

    return 0;

    }

      

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Antenna Placement poj.. 下一篇CCriticalSection的使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: