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的输入, 表示 ...
随机推荐
- 多目标遗传算法 ------ NSGA-II (部分源码解析)两个个体支配判断 dominance.c
/* Domination checking routines */ # include <stdio.h> # include <stdlib.h> # include &l ...
- 学习windows编程 day4 之 矩形的操作
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...
- idea中的常用快捷键
idea中常用的快捷键以及一些奇淫技巧 , 加快我们的开发效率 !!! 知道类名查找你本地以的类 (你pom中依赖的类+你自己创建的类)-------------> ctrl+shi ...
- IDEA中阿里JAVA代码规范插件(P3C)的安装及使用
JAVA代码规范插件(P3C)是阿里巴巴2017年10月14日在杭州云栖大会上首发的,使之前的阿里巴巴JAVA开发手册正式以插件形式公开走向业界.插件的相关信息及安装包都可以在GitHub(https ...
- java keytool证书工具使用小结【转】
java keytool证书工具使用小结 keytool导入导出多条目对比 在Security编程中,有几种典型的密码交换信息文件格式: DER-encoded certificate: .cer, ...
- Study 2 —— 格式化输出
打印人物信息的两种方法第一种: Name = input('Input your name: ') Age = input('Input your age: ') Job = input('Input ...
- plt.scatter(X[0, :], X[1, :], c=Y, s=40, cmap=plt.cm.Spectral)出错
ValueError: c of shape (1, 400) not acceptable as a color sequence for x with size 400, y with size ...
- java类的回顾
1.类是某一批对象的抽象,对象才是一个具体的存在的实体,你我他都是人的实例,而不是人的类.2.类可以包含三种最常见的成员:构造器,成员变量,方法3.4.java世界里,属性,如某个类具有age属性,通 ...
- 20. Spring Boot 默认、自定义数据源 、配置多个数据源 jdbcTemplate操作DB
Spring-Boot-2.0.0-M1版本将默认的数据库连接池从tomcat jdbc pool改为了hikari,这里主要研究下hikari的默认配置 0. 创建Spring Boot项目,选中 ...
- 通过COM组件方式实现java调用C#写的DLL文件 转
最近一段时间单位在做一个Web项目,工程师用JAVA语言,需要公用人员信息,统一用户名和密码,原有的平台中是用C#语言开发的,在网上查找解决方法,通过JAVA调用C#的DLL文件实现.网上资料很多,自 ...