hdu3642 Get The Treasury 线段树--扫描线
Jack knows that there is a great underground treasury in a secret region. And he has a special device that can be used to detect treasury under the surface of the earth. One day he got outside with the device to ascertain the treasury. He chose many different locations on the surface of the earth near the secret region. And at each spot he used the device to detect treasury and got some data from it representing a region, which may contain treasury below the surface. The data from the device at each spot is six integers x1, y1, z1, x2, y2 and z2 (x1<x2, y1<y2, z1<z2). According to the instruction of the device they represent the range of x, y and z coordinates of the region. That is to say, the x coordinate of the region, which may contain treasury, ranges from x1 to x2. So do y and z coordinates. The origin of the coordinates is a fixed point under the ground.
Jack can’t get the total volume of the treasury because these regions don’t always contain treasury. Through years of experience, he discovers that if a region is detected that may have treasury at more than two different spots, the region really exist treasure. And now Jack only wants to know the minimum volume of the treasury.
Now Jack entrusts the problem to you.
题意:问矩形三次以上覆盖的面积
线段树--扫描线裸题,统计1次、2次、3次含以上的长度。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxm=;
typedef long long ll; ll st1[maxm<<],st2[maxm<<],st3[maxm<<];
int cov[maxm<<],y[maxm],z[maxm]; struct rect{
int x1,y1,z1,x2,y2,z2;
}r[]; struct seg{
int x,y1,y2,c;
bool operator < (const seg a)const{
return x<a.x;
}
}s[maxm]; void pushup(int o,int l,int r){
if(cov[o]>=)st1[o]=st2[o]=st3[o]=y[r]-y[l];
else if(cov[o]==){
st1[o]=st2[o]=y[r]-y[l];
if(l+==r)st3[o]=;
else st3[o]=st1[o<<]+st1[o<<|];
}
else if(cov[o]==){
st1[o]=y[r]-y[l];
if(l+==r)st2[o]=st3[o]=;
else{
st2[o]=st1[o<<]+st1[o<<|];
st3[o]=st2[o<<]+st2[o<<|];
}
}
else{
if(l+==r)st1[o]=st2[o]=st3[o]=;
else{
st1[o]=st1[o<<]+st1[o<<|];
st2[o]=st2[o<<]+st2[o<<|];
st3[o]=st3[o<<]+st3[o<<|];
}
}
} void update(int o,int l,int r,seg a){
if(a.y1<=y[l]&&a.y2>=y[r]){
cov[o]+=a.c;
pushup(o,l,r);
return;
}
if(l+==r)return;
int m=l+((r-l)>>);
if(a.y1<y[m])update(o<<,l,m,a);
if(a.y2>y[m])update(o<<|,m,r,a);
pushup(o,l,r);
} int main(){
int T;
scanf("%d",&T);
for(int q=;q<=T;++q){
int n;
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d%d%d%d%d%d",&r[i].x1,&r[i].y1,&r[i].z1,&r[i].x2,&r[i].y2,&r[i].z2);
y[*i-]=r[i].y1;
y[*i]=r[i].y2;
z[*i-]=r[i].z1;
z[*i]=r[i].z2;
}
sort(y+,y+*n+);
sort(z+,z+*n+);
int cntz=,cnty=;
ll ans=;
for(int i=;i<=*n;++i){
if(y[i]!=y[i-])y[++cnty]=y[i];
if(z[i]!=z[i-])z[++cntz]=z[i];
}
for(int i=;i<cntz;++i){
int cnt=;
for(int j=;j<=n;++j){
if(r[j].z1<=z[i]&&r[j].z2>z[i]){
++cnt;
s[cnt].x=r[j].x1;s[cnt].y1=r[j].y1;s[cnt].y2=r[j].y2;
s[cnt].c=;
++cnt;
s[cnt].x=r[j].x2;s[cnt].y1=r[j].y1;s[cnt].y2=r[j].y2;
s[cnt].c=-;
}
}
sort(s+,s+cnt+);
ll sum=;
for(int j=;j<cnt;++j){
update(,,cnty,s[j]);
sum+=st3[]*(s[j+].x-s[j].x);
}
update(,,cnty,s[cnt]);
ans+=sum*(z[i+]-z[i]);
}
printf("Case %d: %lld\n",q,ans);
}
return ;
}
hdu3642 Get The Treasury 线段树--扫描线的更多相关文章
- HDU 3642 Get The Treasury (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...
- BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...
- BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...
- hdu 5091(线段树+扫描线)
上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...
- POJ1151+线段树+扫描线
/* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...
随机推荐
- hdu1693
题解: 还是插头dp 代码: #include<cstdio> #include<cstring> #include<algorithm> #include< ...
- Springboot+MyBatis+mysql+jsp页面跳转详细示例
SpringBoot与MyBatis搭建环境,底层数据库为mysql,页面使用JSP(官网上不推荐使用jsp),完成从数据库中查询出数据,在jsp页面中显示,并且实现页面的跳转功能. 项 ...
- jenkins部署java项目在本地(三)
(1)新建maven构建的java项目 pom.xml的配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...
- TCP拥塞控制和流量控制
TCP 的流量控制与拥塞控制可以说是一体的.流量控制是通过滑动窗口实现的,拥塞避免主要包含以下2个内容: (1)慢开始,拥塞避免 (2)快重传,快恢复 1.流量控制——滑动窗口 TCP采用大小可变 ...
- jdk8-四大函数式接口
jdk8四大核心接口 1.Comsumer接口 2.Function函数型接口 3.断言型接口 4.供给型接口 核心接口的子接口
- rap使用手册
https://github.com/thx/RAP/wiki/user_manual_cn
- mybatis学习(三)----优化Mybatis配置文件中的配置
一.把连接数据库的配置单独放在一个properties文件中 前面我们是把数据库的连接信息放在了mybatis-config.xml中,如下: <?xml version="1.0&q ...
- 20165326 java实验一
<Java程序设计>Java开发环境的熟悉 实验报告 课程:Java程序设计 班级:1653班 姓名:陈卓 学号:20165326 指导教师:娄嘉鹏 实验日期:2018年4月2日 实验时间 ...
- mac下python2.7升级到3.6
1. 前言 Mac系统自带python2.7,本文目的是将自带的python升级到3.6版本. 网上有本多的做法是让python2.7和python3.X两个版本共存,博主并不知道,是两版本共存好,还 ...
- udp协议和socketserver模块
#基于udp协议通讯的套接字# 数据报协议# 一个recvfrom对应一个sendto 一一对应 无粘包产生 # 服务端:# import socket# server=socket.socket(s ...