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 线段树--扫描线的更多相关文章

  1. HDU 3642 Get The Treasury (线段树扫描线,求体积并)

    参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...

  2. 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)

    D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  3. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  4. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  5. HDU 4419 Colourful Rectangle --离散化+线段树扫描线

    题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...

  6. BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤

    3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...

  7. BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞

    看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...

  8. hdu 5091(线段树+扫描线)

    上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...

  9. POJ1151+线段树+扫描线

    /* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...

随机推荐

  1. zookeeper集群环境搭建(纯zookeeper)

    1.首先在三台机子上放上zookeeper的解压包,解压. 然后的话zookeeper是依赖于jdk的,那么也应该安装jdk,这里不详细说明了. mv zookeeper-3.4.5 zookeepe ...

  2. TCP/IP协议 计算机间的通讯,传输、socket 传输通道

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- #TCP/IP简介 #为了把全世界的所有不同类型的计算机都连接起来,就必须规定一套全球通用的协议,为了实现 ...

  3. Cracking The Coding Interview2.3

    #include <iostream> #include <string> using namespace std; class linklist { private: cla ...

  4. html、xhtml、html5的区别

    1.HTML:HyperText Mark-up Language(超文本标记语言)构成网页的主要语言  常指:HTML 4.012.XHTLM:EXtensible HyperText Mark-u ...

  5. 3.8 C++继承机制下的析构函数

    参考:http://www.weixueyuan.net/view/6365.html 总结: 构造函数的执行顺序是按照继承顺序自顶向下的,从基类到派生类,而析构函数的执行顺序是按照继承顺序自下向上, ...

  6. do文件的编写(转)

    以前在使用ModelSim进行仿真的时候,一直是使用其GUI进行操作的,但是这样很繁琐也很费时.故希望学习其自动化仿真do文件,下面是学习的一些总结. 一.编写基本的do文件 下面按照实际仿真的步骤来 ...

  7. 强化学习3-蒙特卡罗MC

    之前讲到强化学习可以用马尔科夫决策过程来描述,通常情况下,马尔科夫需要知道  {S A P R γ},γ是衰减因子,那为什么还需要蒙特卡罗呢? 首先什么是蒙特卡罗? 蒙特卡罗实际上是一座赌城的名字,蒙 ...

  8. codeforces959C

    题意:输入n(代表有n个节点),找出满足题意给出的找出最小节点数(对于给出的所有边,在这个最小节点数集合里总可以找到一个点在此边上). 给出算法: 1:根节点节点数为1; 2:计算所有深度为偶数的节点 ...

  9. 四、使用汇编编写LED裸机驱动

    1. 确定硬件连接 打开OK6410底板电路图,找到LED,可以发现NLEDx为0时LED点亮. 找到LED的控制引脚,发现LED控制引脚通过连接器连到了核心板: 打开核心板电路图,找到对应的连接器中 ...

  10. python day 07-数据类型补充,集合,深浅拷贝

    一.基础数据类型补充 1.列表转字符串 a='A'.join(['c','c','s']) print(a) 2.循环删除列表中的每⼀一个元素 lst=['asdf','dftgst','zsdrfs ...