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

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

每块蔬菜地种植蔬菜收获的利润为 val=x*y*price。  面积乘以价格,题目的重点转换在于如何确定重叠区域怎么让它种植最贵的蔬菜。

观察利润计算公式 :   x*y*price <==> x*y*h    可以转换为求体积并。

体积并其实和面积并基本一样,将体积的范围记录下来,每一层遍历求面积并,结果就是底面积乘每一层的高之和

#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<<],len[MAXN<<]; 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<<],tmp[MAXN<<]; void PushUp(int rt,int l,int r)
{
if(col[rt])
{
len[rt] = hh[r+] - hh[l];
}
else if(l==r) len[rt] = ;
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)>>;
if(L <= mid) update(val,L,R,l,mid,ls);
if(R > mid) update(val,L,R,mid+,r,rs);
PushUp(rt,l,r);
} int main()
{
int n,i,j,t,kase=;
double ans;
sf("%d",&t);
while(t--)
{
sf("%d%d",&n,&m);
int v=;
for(i=;i<=m;i++)
sf("%d",&V[i]);
for(i=;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,,V[r]);
hh[++v]=y2;
a[v]=node(y1,y2,x2,-,V[r]);
}
sort(hh+,hh++v);
sort(a+,a++v);
int d=;
for(i=;i<=v;i++)
if(hh[i]!=hh[i-])
hh[++d]=hh[i];
double ans=;
V[]=;
sort(V,V+m+);
int ct =;
for(j=;j<=m;j++)
{
ct=;
for(i=;i<=v;i++)
if(a[i].v>V[j-])
tmp[ct++]=a[i];
mem(col,);
mem(len,);
for(i=;i<ct-;i++)
{
//int l=BinarySearch(tmp[i].l,1,M);
//int r=BinarySearch(tmp[i].r,1,M)-1;
int l = lower_bound(hh+,hh+d,tmp[i].l)-hh;
int r = lower_bound(hh+,hh+d,tmp[i].r)-hh-;
if(l<=r) update(tmp[i].c,l,r,,d,);
ans+=len[]*(double)(V[j]-V[j-])*(tmp[i+].x-tmp[i].x);
}
}
pf("Case %d: %.0lf\n",kase++,ans);
}
return ;
}

hdu 3255 体积并的更多相关文章

  1. hdu 3255 Farming(扫描线)

    题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...

  2. HDU 3255 扫描线(立方体体积并变形)

    Farming Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  3. HDU 3255 Farming (线段树+扫面线,求体积并)

    题意:在一块地上种蔬菜,每种蔬菜有个价值.对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值. 思路:将蔬菜的价值看做高度的话,题目就转化成求体积并,这样就容易了. 与HDU 3642 Get ...

  4. HDU 3255 Farming

    矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...

  5. hdu 3642 体积并

    题意:求三个矩形体积的并 链接:点我 枚举z #include<stdio.h> #include<iostream> #include<stdlib.h> #in ...

  6. HDU 2002 计算球体积

    题目链接:HDU 2002 Description 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径. Output 输出对应的球的体积,对于每 ...

  7. HDU 1411--校庆神秘建筑(欧拉四面体体积计算)

    校庆神秘建筑 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

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

    Get The Treasury Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

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

    给出n个立方体,要你求这些立方体至少被覆盖三次的部分. 先把这个立方体的信息存在来,发现Z的范围不大,z范围是是[-500,500],所以我们可以先离散化,然后枚举Z, 然后对于每一段Z的区域内,在当 ...

随机推荐

  1. 【Es】jest操作elasticsearch

    https://blog.csdn.net/niuchenliang524/article/details/82869319 操作es的客房端有多个,在此例出三种(具体区别自行百度),本文讲的是jes ...

  2. 魔方方法之--类的构造(__init__,__new__)和析构(__del__)方法

    构造方法(参见小甲鱼入门教程) __ init__()方法:类的初始化方法,初始化类对象时被调用,需要的时候再调用它 注意点:这个方法的返回值必须是None class Rectangle(): de ...

  3. 公共子序列(luogu P1439)

    传送门 题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输出格式 输入格式: 第一行是一个数n, 接下来两行,每行为n个数,为自然数1-n的一个排列. 输出格式: 一个数,即最 ...

  4. 【BZOJ3417】[POI2013]MOR-Tales of seafaring (最短路SPFA)

    [POI2013]MOR-Tales of seafaring 题目描述 一个n点m边无向图,边权均为1,有k个询问 每次询问给出(s,t,d),要求回答是否存在一条从s到t的路径,长度为d 路径不必 ...

  5. 洛谷 P2234 [HNOI2002]营业额统计

    题目描述 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额.分析营业情况是 ...

  6. Tomcat 配置文件的解析

    转载:https://www.cnblogs.com/sunshine-1/p/8990044.html https://www.cnblogs.com/kismetv/p/7228274.html ...

  7. 51nod - 1163 巧妙的并查集 O(1)维护区间

    有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励.在结束时间之前完成该任务,就可以获得对应的奖励.完成每一个任务所需的时间都是1个单位时间.有时候完成所有任务是不可能的,因为时间上可能会有冲突 ...

  8. UVA - 11795 状压DP

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...

  9. docker jenkins安装(一)

    https://hub.docker.com/r/jenkins/jenkins  jenkins的docker官方镜像地址 https://jenkins.io/  jenkins官方网站 环境: ...

  10. pandas中,dataframe 进行数据合并-pd.concat()

    ``# 通过数据框列向(左右)合并 a = pd.DataFrame(X_train) b = pd.DataFrame(y_train) # 合并数据框(合并前需要将数据设置成DataFrame格式 ...