HDU 3255 扫描线(立方体体积并变形)
Farming
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1375 Accepted Submission(s): 402
Each person works in a rectangular piece of land, seeding one seed in one unit square. The working areas of different people may overlap, so one unit square can be seeded several times. However, due to limited space, different seeds in one square fight each other -- finally, the most powerful seed wins. If there are several "most powerful" seeds, one of them win (it does not matter which one wins).
There are m kinds of seeds. Different seeds grow up into different vegetables and sells for different prices.
As a rule, more powerful seeds always grow up into more expensive vegetables.
Your task is to calculate how much money will you get, by selling all the vegetables in the whole farm.
Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3).
The next line contains m distinct positive integers pi (1 <= pi <= 100), the prices of each kind of vegetable.
The vegetables (and their corresponding seeds) are numbered 1 to m in the order they appear in the input.
Each of the following n lines contains five integers x1, y1, x2, y2, s, indicating a working seeded a rectangular area with lower-left corner (x1,y1), upper-right corner (x2,y2), with the s-th kind of seed.
All of x1, y1, x2, y2 will be no larger than 106 in their absolute values.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 30005
#define ll root<<1
#define rr root<<1|1
#define mid (a[root].l+a[root].r)/2 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} struct node{
int l, r, val, sum;
}a[N*]; struct Line{
int x1, x2, y, val;
Line(){}
Line(int a,int b,int c,int d){
x1=a;
x2=b;
y=c;
val=d;
}
}line[N*]; bool cmp(Line a,Line b){
return a.y<b.y;
} struct Cube{
int x1, y1, z1, x2, y2, z2;
}cu[N]; int n, m;
int p[];
int xx[N*];
int zz[N*];
int nx, nz; int b_s(int key){
int l=, r=nx-;
while(l<=r){
int mm=(l+r)/;
if(xx[mm]==key) return mm;
else if(xx[mm]>key) r=mm-;
else if(xx[mm]<key) l=mm+;
}
} void build(int l,int r,int root){
a[root].l=l;
a[root].r=r;
a[root].val=a[root].sum=;
if(l==r) return;
build(l,mid,ll);
build(mid+,r,rr);
} void up(int root){
if(a[root].val) a[root].sum=xx[a[root].r+]-xx[a[root].l];
else if(a[root].l==a[root].r) a[root].sum=;
else a[root].sum=a[ll].sum+a[rr].sum;
} void update(int l,int r,int val,int root){
if(a[root].l==l&&a[root].r==r){
a[root].val+=val;
up(root);
return;
}
if(r<=a[ll].r) update(l,r,val,ll);
else if(l>=a[rr].l) update(l,r,val,rr);
else{
update(l,mid,val,ll);
update(mid+,r,val,rr);
}
up(root);
} main()
{
int t, i, j, k;
int kase=;
cin>>t;
while(t--){
scanf("%d %d",&n,&m);
for(i=;i<=m;i++) scanf("%d",&p[i]);
nx=nz=;
for(i=;i<n;i++){
scanf("%d %d %d %d %d",&cu[i].x1,&cu[i].y1,&cu[i].x2,&cu[i].y2,&cu[i].z2);
cu[i].z1=;
cu[i].z2=p[cu[i].z2];
xx[nx++]=cu[i].x1;
xx[nx++]=cu[i].x2;
zz[nz++]=cu[i].z1;
zz[nz++]=cu[i].z2;
}
sort(xx,xx+nx);
sort(zz,zz+nz);
nx=unique(xx,xx+nx)-xx;
nz=unique(zz,zz+nz)-zz;
__int64 ans=;
for(i=;i<nz;i++){
k=;
for(j=;j<n;j++){
if(cu[j].z1<=zz[i-]&&cu[j].z2>=zz[i]){
line[k++]=Line(cu[j].x1,cu[j].x2,cu[j].y1,);
line[k++]=Line(cu[j].x1,cu[j].x2,cu[j].y2,-);
}
}
sort(line,line+k,cmp);
build(,nx,);
__int64 num=;
for(j=;j<k-;j++){
update(b_s(line[j].x1),b_s(line[j].x2)-,line[j].val,);
num+=(__int64)a[].sum*(__int64)(line[j+].y-line[j].y);
}
ans+=num*(__int64)(zz[i]-zz[i-]);
}
printf("Case %d: %I64d\n",kase++,ans);
}
}
HDU 3255 扫描线(立方体体积并变形)的更多相关文章
- hdu 3255 Farming(扫描线)
题目链接:hdu 3255 Farming 题目大意:给定N个矩形,M个植物,然后给定每一个植物的权值pi,pi表示种植物i的土地,单位面积能够收获pi,每一个矩形给定左下角和右上角点的坐标,以及s, ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- HDU 3642 扫描线(立方体体积并)
Get The Treasury Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3265 扫描线(矩形面积并变形)
Posters Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 3255 体积并
http://www.cnblogs.com/kane0526/archive/2013/03/07/2948446.html http://blog.csdn.net/acdreamers/arti ...
- HDU 3255 Farming (线段树+扫面线,求体积并)
题意:在一块地上种蔬菜,每种蔬菜有个价值.对于同一块地蔬菜价值高的一定是最后存活,求最后的蔬菜总值. 思路:将蔬菜的价值看做高度的话,题目就转化成求体积并,这样就容易了. 与HDU 3642 Get ...
- HDU 3255 Farming
矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...
- HDU 2002 计算球体积
题目链接:HDU 2002 Description 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径. Output 输出对应的球的体积,对于每 ...
- hdu 1542 扫描线求矩形面积的并
很久没做线段树了 求矩形面积的并分析:1.矩形比较多,坐标也很大,所以横坐标需要离散化(纵坐标不需要),熟悉离散化后这个步骤不难,所以这里不详细讲解了,不明白的还请百度2.重点:扫描线法:假想有一条扫 ...
随机推荐
- mysql 锁的粒度
1.锁的类型分为读锁和写锁,这个很好区分.可以这样认为:如果有增删改,就是写锁.如果是查询,就是读锁.2.锁的粒度也就是锁的范围,分为行锁和表锁.锁的范围和多个因素有关,包括事务隔离级别.是否使用索引 ...
- openerp安装记录及postgresql数据库问题解决
ubuntu-14.04下openerp安装记录1.安装PostgreSQL 数据库 a.安装 sudo apt-get install postgresql 安装后ubu ...
- Python变量类型
Python变量类型 变量是存储在内存中的值,因此在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定的内存,并决定什么数据可以被存储在内存中. 因此变量可以指定不同的数据类型, ...
- z-index总结【转载http://www.cnblogs.com/mind/archive/2012/04/01/2198995.html】
元素位置重叠的背景常识 (x)html文档中的元素默认处于普通流(normal flow)中,也就是说其顺序由元素在文档中的先后位置决定,此时一般不会产生重叠(但指定负边距可能产生重叠).当我们用cs ...
- SDL2.0的加载图片贴图
加载图片贴图,采用了SDL_Window.SDL_Renderer.SDL_Texture和SDL_Image库 实例: #include <stdio.h> #include <m ...
- HBase的shell命令行界面按退格键(Backspace)无法删除问题
在HBase的shell命令行界面输入错误项按"退格键"删除,却怎么也删除不了: 解决办法: 第一步,修改SecureCRT的设置参数: 第二步,按"Ctrl+退格键(B ...
- linux笔记:RPM软件包管理-rpm命令管理
rpm包命名原则: rpm包的依赖性: 包名和包全名: rpm软件包安装.升级和卸载: rpm软件包查询: 从rpm包中提取指定文件:
- 能源项目xml文件标签释义--DataSource
<bean id="dataSource1" class="org.apache.tomcat.jdbc.pool.DataSource" destroy ...
- 制作ubuntu安装u盘
Ubuntu官方中文译名为友帮拓,是一款开源免费的linux操作系统.与其他的linux操作系统不同之处在于Ubuntu的软件包清单只包含那些高质量的重要应用程序,因此深受广大linux用户的喜爱,那 ...
- DSP EPWM学习笔记1 - EPWM定时中断
DSP EPWM学习笔记1 - EPWM定时中断 彭会锋 EPWM模块组成 EPWM有7个子模块组成:时间基准 TB.比较功能 CC.动作限定 AQ.死区产生 DB.斩波控制 PC.故障捕获 TZ.事 ...