hdu3255扫描线:带权面积交转体积交
手贱把i打成j,调了半天
/*
面积并转体积并,长方体高度为作物价格
算体积并:在笛卡尔坐标系的y轴上建立线段树cnt记录区间被完全覆盖的次数,sum记录区间被覆盖的总长度
以平行于xoy的平面从下往上扫描,把穿过扫描面的长方体的上下边加入集合segs,对集合segs里的边排序,然后一根扫描线从下往上扫描
另外,更新是不影响线段边界的
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#define ll long long
#define maxn 30000*2+10
#define lson l,m,rt<<1
#define rson m,r,rt<<1|1
using namespace std;
struct Seg{
int l,r,h,c;
Seg(){}
Seg(int a,int b,int c,int d):l(a),r(b),h(c),c(d){}
bool operator<(const Seg & a)const{
return h<a.h;
}
}segs[maxn];
struct cube{
int x1,y1,z1,x2,y2,z2;
cube(){}
cube(int a,int b,int c,int d,int e,int f):x1(a),y1(b),z1(c),x2(d),y2(e),z2(f){}
}cubes[maxn];
int seeds[],n,m;
int y[maxn<<],toty,tot;
int z[maxn],totz;
map<int,int>mp;
ll cnt[maxn<<],len[maxn<<];
void init(){
tot=toty=totz=;
mp.clear();
memset(cnt,,sizeof cnt);
memset(len,,sizeof len);
} inline void pushup(int rt,int l,int r){
if(cnt[rt]){
len[rt]=y[r]-y[l];
}
else if(l+==r) len[rt]=;
else len[rt]=len[rt<<]+len[rt<<|];
}
void update(int L,int R,int c,int l,int r,int rt){
if(L<=l && R>=r){
cnt[rt]+=c;
pushup(rt,l,r);
return;
}
int m=l+r>>;
if(L<m) update(L,R,c,lson);
if(R>m) update(L,R,c,rson);
pushup(rt,l,r);
}
int main(){
int T,a,b,c,d,e;
cin >> T;
for(int tt=;tt<=T;tt++){
init();
cin >> n >> m;
for(int i=;i<=m;i++)scanf("%d",&seeds[i]);
z[tot++]=;//把地平线加上!
for(int i=;i<=n;i++){
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
cubes[i]=cube(a,b,,c,d,seeds[e]);
z[totz++]=seeds[e];
y[toty++]=b;y[toty++]=d;
}
z[totz++]=;
sort(z,z+totz);totz=unique(z,z+totz)-z;//离散化z轴
sort(y,y+toty);toty=unique(y,y+toty)-y;//离散化x轴
for(int i=;i<toty;i++) mp[y[i]]=i; ll res=;
for(int i=;i<totz-;i++){
tot=;//初始化
memset(segs,,sizeof segs);
/* memset(cnt,0,sizeof cnt);
memset(len,0,sizeof len); */ for(int j=;j<=n;j++){//遍历所有cubes,把符合条件的加进去
if(cubes[j].z1<=z[i] && cubes[j].z2>=z[i+]){
segs[tot++]=Seg(cubes[j].y1,cubes[j].y2,cubes[j].x1,);
segs[tot++]=Seg(cubes[j].y1,cubes[j].y2,cubes[j].x2,-);
}
}
sort(segs,segs+tot);
for(int j=;j<tot;j++){
if(j!=)
res+=(ll)(z[i+]-z[i])*(segs[j].h-segs[j-].h)*len[];
update(mp[segs[j].l],mp[segs[j].r],segs[j].c,,toty-,); }
}
printf("Case %d: %lld\n",tt,res);
}
return ;
}
hdu3255扫描线:带权面积交转体积交的更多相关文章
- 51nod1459(带权值的dijkstra)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1459 题意:中文题诶- 思路:带权值的最短路,这道题数据也没 ...
- POJ 1703 Find them, Catch them(带权并查集)
传送门 Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42463 Accep ...
- Java数据结构——带权图
带权图的最小生成树--Prim算法和Kruskal算法 带权图的最短路径算法--Dijkstra算法 package graph; // path.java // demonstrates short ...
- 带权图的最短路径算法(Dijkstra)实现
一,介绍 本文实现带权图的最短路径算法.给定图中一个顶点,求解该顶点到图中所有其他顶点的最短路径 以及 最短路径的长度.在决定写这篇文章之前,在网上找了很多关于Dijkstra算法实现,但大部分是不带 ...
- [NOIP摸你赛]Hzwer的陨石(带权并查集)
题目描述: 经过不懈的努力,Hzwer召唤了很多陨石.已知Hzwer的地图上共有n个区域,且一开始的时候第i个陨石掉在了第i个区域.有电力喷射背包的ndsf很自豪,他认为搬陨石很容易,所以他将一些区域 ...
- poj1417 带权并查集 + 背包 + 记录路径
True Liars Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2713 Accepted: 868 Descrip ...
- poj1984 带权并查集(向量处理)
Navigation Nightmare Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 5939 Accepted: 2 ...
- 【BZOJ-4690】Never Wait For Weights 带权并查集
4690: Never Wait for Weights Time Limit: 15 Sec Memory Limit: 256 MBSubmit: 88 Solved: 41[Submit][ ...
- hdu3038(带权并查集)
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=3038 题意: n表示有一个长度为n的数组, 接下来有m行形如x, y, d的输入, 表示 ...
随机推荐
- 20190417 Spring Security
参考资料 Spring-Security的4.2.12版本官方文档 Spring Security简介
- CM记录-CDH故障修复处理记录
CDH大数据集群修复记录 1)cm web打不开,查看监听7180端口产生了很多进程,于是kill进程:重启cloudera-cmf-server服务,几秒钟就挂了,查看cloudera-scm-se ...
- mybatis中Parameter index out of range (1 > number of parameters, which is 0).
Parameter index out of range (1 > number of parameters, which is 0).(参数索引超出范围) 在mybatis里面写就是应该是 l ...
- jquery 遍历 json【转】
jquery 遍历 json <HTML> <HEAD> <meta http-equiv="content-Type" content=" ...
- Study 7 —— while循环中止语句
循环的终止语句break #用于完全结束一个循环,跳出循环体执行循环后面的语句continue #只终止本次循环,接着执行后面的循环 1. 打印0-100,截止到第6次 count = 0 while ...
- synchronized实现原理
线程安全是并发编程中的重要关注点,应该注意到的是,造成线程安全问题的主要诱因有两点,一是存在共享数据(也称临界资源),二是存在多条线程共同操作共享数据.因此为了解决这个问题,我们可能需要这样一个方案, ...
- jquery 兼容的滚轮事件
// jquery 兼容的滚轮事件 $(document).on("mousewheel DOMMouseScroll", function (e) { ? : -)) || // ...
- SpringBoot使用外置的Servlet容器
SpringBoot默认使用嵌入式的Servlet容器,应用打包成可执行的jar包 优点:简单.便携 缺点:默认不支持jsp,优化定制比较复杂(使用定制器serverProperties.自定义Emb ...
- 【C++】结构体、联合体大小计算
struct结构体大小计算 struct A { char a; int b; char c; } 这个结构体中,char占据1字节,int占据4字节,char占据1字节,而这组数据结构的大小是12字 ...
- 嵌入式linux系统中,lsusb出现unable to initialize libusb: -99 解决办法 【转】
转自:http://cpbest.blog.163.com/blog/static/41241519201111575726966/ libusb是linux系统中,提供给用户空间访问usb设备的AP ...