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的输入, 表示 ...
随机推荐
- selenium_采集药品数据
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- P2422 良好的感觉
P2422 良好的感觉 给定一段序列, 其中元素 \(0 \leq a_{i} \leq 100000\) 定义一段子段 \([L, R]\) 的舒适值为 \(\min_{L \leq i \leq ...
- yolov2源码分析
分析过程首先我们从yolo的训练命令开始分析(yolo的源码是用c++写的): ./darknet detector train cfg/voc.data cfg/yolo-voc.cfg darkn ...
- GoLang基础数据类型--->字符串处理大全
GoLang基础数据类型--->字符串处理大全 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入: 高级运维工程师之路 59843264 ...
- Ansible拷贝文件遇到的问题
ansible报错Aborting, target uses selinux but python bindings (libselinux-python) aren't installed 报错内容 ...
- Java Calendar详解
网上看到的一篇,码一下.侵删 一:字段和方法的信息 YEAR 字段: public static final int YEAR ; 指示年的 get 和 set 的字段数字.这是一个特定于日历的值: ...
- js设定延迟时间的函数
1.如果想要在执行一个js函数之前延迟一段时间应该怎么做? 答:"setTimeout('update()',1000);" 其中update()函数就是延迟后执行的函数,后面的时 ...
- Nginx URL匹配
Nginx 下 location模块 可以实现对网页URL进行分析处理 location ~ .*\.(gif|jpg|jpeg|png|bmg|swf)$ { // 扩展名为gif|jpg|j ...
- C++使用目录
VS2017的安装和配置 常用指令 C++ 数据类型 常量 运算符 数组 字符串 Ansi与Unicode 指针 模态与非模态对话框 变量的引用& new和delete动态分配和 ...
- UBUNTU18.04安装网易云音乐并直接图标启动
这是一个网友改的程序,安装好以后把 ~/.cache/netcase-cloud-music 这个目录删除掉,就可以正常使用了,不用root权限