hdu 3255 体积并

http://www.cnblogs.com/kane0526/archive/2013/03/07/2948446.html

http://blog.csdn.net/acdreamers/article/details/11854781

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define MAXN 160000+5
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue
#define INF 0x3f3f3f3f

#define ls (rt<<1)
#define rs (rt<<1|1)

int n,m;

double hh[MAXN],col[MAXN<<3],len[MAXN<<3];

int V[MAXN];

struct node
{
    double l,r,x,c;
    int v;
    node(){}
    node(double a,double b,double c,double d,int e):l(a),r(b),x(c),c(d),v(e){}
    bool operator < (const node &b) const
    {
        return x<b.x;
    }
}a[MAXN<<3],tmp[MAXN<<3];

void PushUp(int rt,int l,int r)
{
    if(col[rt])
    {
        len[rt] = hh[r+1] - hh[l];
    }
    else if(l==r) len[rt] = 0;
    else
    {
        len[rt] = len[ls]+len[rs];
    }
}

void update(int val,int L,int R,int l,int r,int rt)
{
    if(L<=l && r<=R)
    {
        col[rt] += val;
        PushUp(rt,l,r);
        return;
    }
    int mid = (l+r)>>1;
    if(L <= mid) update(val,L,R,l,mid,ls);
    if(R > mid) update(val,L,R,mid+1,r,rs);
    PushUp(rt,l,r);
}

int main()
{
    int n,i,j,t,kase=1;
    double ans;
    sf("%d",&t);
    while(t--)
    {
        sf("%d%d",&n,&m);
        int v=0;
        for(i=1;i<=m;i++)
        sf("%d",&V[i]);
        for(i=1;i<=n;i++)
        {
            double x1,x2,y1,y2;
            int r;
            sf("%lf%lf%lf%lf%d",&x1,&y1,&x2,&y2,&r);
            hh[++v]=y1;
            a[v]=node(y1,y2,x1,1,V[r]);
            hh[++v]=y2;
            a[v]=node(y1,y2,x2,-1,V[r]);
        }
        sort(hh+1,hh+1+v);
        sort(a+1,a+1+v);
        int d=1;
        for(i=2;i<=v;i++)
            if(hh[i]!=hh[i-1])
                hh[++d]=hh[i];
        double ans=0;
        V[0]=0;
        sort(V,V+m+1);
        int ct =0;
        for(j=1;j<=m;j++)
        {
            ct=0;
            for(i=1;i<=v;i++)
                if(a[i].v>V[j-1])
                    tmp[ct++]=a[i];
            mem(col,0);
            mem(len,0);
            for(i=0;i<ct-1;i++)
            {
                //int l=BinarySearch(tmp[i].l,1,M);
                //int r=BinarySearch(tmp[i].r,1,M)-1;
                int l = lower_bound(hh+1,hh+d,tmp[i].l)-hh;
                int r = lower_bound(hh+1,hh+d,tmp[i].r)-hh-1;
                if(l<=r) update(tmp[i].c,l,r,1,d,1);
                ans+=len[1]*(double)(V[j]-V[j-1])*(tmp[i+1].x-tmp[i].x);
            }
        }
        pf("Case %d: %.0lf\n",kase++,ans);
    }
    return 0;
}
时间: 2024-10-28 20:55:40

hdu 3255 体积并的相关文章

hdu 3255 Farming(扫描线)

题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s,s表示该矩形能够中植物s.问说总的最大收益. 解题思路:由于一块仅仅能种一种植物,所以对于一块重叠的土地,要选取收益最大的植物种植.除去这一点,剩下的就是线段树扫描线的应用了.那对于pi能够视为第三维坐标,而植物的种类仅仅有3种,所以直接离散化就可以,注意要依照植物收益的权值大小离散. #inclu

hdu 3255 Farming(线段树求体积并)

Farming Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1445    Accepted Submission(s): 428 Problem Description You have a big farm, and you want to grow vegetables in it. You're too lazy to s

hdu 3642 体积并

题意:求三个矩形体积的并 链接:点我 枚举z 1 #include<stdio.h> 2 #include<iostream> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<algorithm> 6 #include<vector> 7 #include<math.h> 8 #include<map> 9 #pragma comment(linker,

扫描线题目汇总 (里面的题解和代码非原创)

hdu 3867 Light and Shadow 转载自:http://blog.csdn.net/accry/article/details/6676009 题意: 原子弹爆炸,一些互不相交的线段,求能辐射到的线段个数(可以将原子弹爆炸点视为泛光源) 分析: 以辐射源为中心对周围的点按照极坐标角度进行排序,然后在极坐标上使用扫描线方法.维护一个集合,集合内的元素是与扫描线相交的线段,排序依据是线段与扫描线的交点到辐射源的距离.该集合中的最小元素就是被照射到的线段. 有关容器(set)排序依据

POJ 3255 &amp;&amp; HDU 1688 &amp;&amp; HDU 3191 次短路问题

POJ 3255 Roadblocks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7627   Accepted: 2798 Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old h

hdu 2002 计算球体积

计算球体积 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 102749    Accepted Submission(s): 42550 Problem Description 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径. Output 输出对应的球的体积,对于每组输入数据

hdu 1411(四面体的体积)

校庆神秘建筑 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2087    Accepted Submission(s): 693 Problem Description 杭 州电子科技大学即将迎来50周年的校庆,作为校庆委员会成员的我被上级要求设计一座神秘的建筑物来迎合校庆,因此我苦思冥想了一个月,终于设计出了一套方 案,这座建筑物有

HDU 3642 扫描线(立方体体积并)

Get The Treasury Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2190    Accepted Submission(s): 669 Problem Description Jack knows that there is a great underground treasury in a secret region

Get The Treasury HDU - 3642(体积扫描线)

给出n个立方体,要你求这些立方体至少被覆盖三次的部分. 先把这个立方体的信息存在来,发现Z的范围不大,z范围是是[-500,500],所以我们可以先离散化,然后枚举Z, 然后对于每一段Z的区域内,在当前的区域内对xoy轴使用一次扫描线,找到当前这个区域内被覆盖三次的体积,然后每次枚举Z,每次相加,就是最后的答案. #include<map> #include<set> #include<ctime> #include<cmath> #include<s