HDU 3642 Get The Treasury 【线段树】【扫描线】
来源:互联网 发布:电视剧硅谷中的算法 编辑:程序博客网 时间:2024/06/06 23:51
题目:点击打开链接
题意:求空间内至少三个长方体重叠相交的体积
分析:我们可以先把所有的长方体的两点的x,y,z保存下来,因为给出的长方体坐标x,y,z,z很小,所以可以考虑离散化z,然后对于每一个z,利用扫描线计算出所有长方体的高包含z的长方体的x,y面的面积,该面积也要求至少重叠三次,然后这一段的重叠的体积就是重叠面积乘上z与下一个z的高度差。
//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <cmath>#include <cstring>#include <algorithm>#include <queue>#include <set>#include <vector>#include <map>#define PR pair<int,int>#define MP make_pair#define fi first#define se second#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define sqr(x) ((x)*(x))#define ll __int64const ll INF=1e18;const int inf=0x3f3f3f3f;const int M=18;const int N=2010;const int MOD=1000000007;const double eps=1e-6;const double pi=acos(-1.0);using namespace std;struct node{ int x,y,z; node(int _x=0,int _y=0,int _z=0):x(_x),y(_y),z(_z){};}a[N],b[N];struct Seg{ int l,r,h,f; Seg(int _l=0,int _r=0,int _h=0,int _f=0):l(_l),r(_r),h(_h),f(_f){};}seg[N];bool cmp(Seg a,Seg b){ return a.h<b.h;}int n;ll len[N<<2],twice[N<<2],third[N<<2],flag[N<<2];vector<int> X,Z;int getid(int x) {return lower_bound(X.begin(),X.end(),x)-X.begin()+1;}void pushup(int l,int r,int rt){ if(flag[rt]) len[rt]=X[r]-X[l-1]; else if(l==r) len[rt]=0; else len[rt]=len[rt<<1]+len[rt<<1|1]; if(flag[rt]>1) twice[rt]=X[r]-X[l-1]; else if(l==r) twice[rt]=0; else if(flag[rt]==1) twice[rt]=len[rt<<1]+len[rt<<1|1]; else twice[rt]=twice[rt<<1]+twice[rt<<1|1]; if(flag[rt]>2) third[rt]=X[r]-X[l-1]; else if(l==r) third[rt]=0; else if(flag[rt]==2) third[rt]=len[rt<<1]+len[rt<<1|1]; else if(flag[rt]==1) third[rt]=twice[rt<<1]+twice[rt<<1|1]; else third[rt]=third[rt<<1]+third[rt<<1|1];}void update(int L,int R,int x,int l,int r,int rt){ if(L<=l&&r<=R) { flag[rt]+=x; pushup(l,r,rt); return; } int m=l+r>>1; if(L<=m) update(L,R,x,lson); if(m<R) update(L,R,x,rson); pushup(l,r,rt);}int main(){ int i,j,T,cas=0; scanf("%d",&T); while(T--) { scanf("%d",&n); X.clear();Z.clear(); for(i=1;i<=n;i++) { int x1,x2,y1,y2,z1,z2; scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2); X.push_back(x1);X.push_back(x2); Z.push_back(z1),Z.push_back(z2); a[i]=node(x1,y1,z1); b[i]=node(x2,y2,z2); } if(n<3) {printf("Case %d: 0\n",++cas);continue;} sort(Z.begin(),Z.end()); Z.erase(unique(Z.begin(),Z.end()),Z.end()); sort(X.begin(),X.end()); X.erase(unique(X.begin(),X.end()),X.end()); ll ans=0; for(i=0;i<(int)Z.size();i++) { int cnt=0; ll res=0; for(j=1;j<=n;j++) { if(a[j].z<=Z[i]&&b[j].z>Z[i]) { seg[++cnt]=Seg(a[j].x,b[j].x,a[j].y,1); seg[++cnt]=Seg(a[j].x,b[j].x,b[j].y,-1); } } sort(seg+1,seg+1+cnt,cmp); for(j=1;j<=cnt;j++) { int l=getid(seg[j].l); int r=getid(seg[j].r)-1; update(l,r,seg[j].f,1,(int)X.size(),1); res+=third[1]*(seg[j+1].h-seg[j].h); } ans+=res*(Z[i+1]-Z[i]); } printf("Case %d: %I64d\n",++cas,ans); }}
0 0
- HDU 3642 Get The Treasury 【线段树】【扫描线】
- hdu 3642 Get The Treasury(扫描线)
- HDU 3642 Get The Treasury (线段树、扫描线求立方体体积交)
- HDU 3642 Get The Treasury(离散化+线段树:扫描线)
- HDU 3642 Get The Treasury[离散化 + 扫描线 + 线段树]
- HDU 3642 Get The Treasury(体积并+覆盖三次+线段树+扫描线)
- HDU 3642——Get The Treasury(线段树+扫描线+离散化+体积交多次)
- HDU 3642 Get The Treasury (线段树扫描线进阶--求长方体重叠3次或以上的体积)
- HDU 3642 Get The Treasury(线段树+扫描线求面积【再升级版(三维)】)
- hdu 3642 Get The Treasury (三维的扫描线)
- hdu 3642 Get The Treasury(扫描线、立方体交)
- hdoj 3642 Get The Treasury 【线段树 扫描线 求立方体积交】
- hdu 3642 Get The Treasury(线段树求体积并)
- hdu-3642--Get The Treasury-线段树求面积并
- HDU 3642 Get The Treasury(线段树)
- hdu3642 Get The Treasury--线段树 & 扫描线 & 面积并(待解决)
- 【hdu3642】Get The Treasury (立方体体积交+线段树+扫描线)
- hdu3642-Get The Treasury 线段树+扫描线+离散化 求三维体积并
- 能否在一个构造器中调用另一个构造器
- poj 1201 Intervals
- oracle的增删改插和子查询
- 设计模式笔记——策略设计模式
- ViewFlipper 视图容器
- HDU 3642 Get The Treasury 【线段树】【扫描线】
- opencv如何进行摄像头标定
- hbase安装说明
- opencv学习(十四)之图像颜色通道分离和融合
- Java金融信息交换引擎 QuickFIX/J
- Bean和Map的互转+Demo
- 狡猾的商人_bzoj1202_差分约束
- Hadoop安装说明
- c#中单元测试