首页 > 其他分享 >立方体积重叠

立方体积重叠

时间:2023-08-24 10:00:48浏览次数:47  
标签:pr 重叠 rs xx length 体积 ls 立方 pl

Smiling & Weeping

             ---- 在世人中间不愿渴死的人,必须学会从一切杯子里痛饮;

               在世人中间要保持清洁的人,必须懂得用脏水也可以洗身。

 

题目链接:Problem - 3642 (hdu.edu.cn)

思路:扫描线

Talk is cheap , show me the code

  1 #include<bits/stdc++.h> // 在hdu提交的话,头文件要改一下
  2 using namespace std;
  3 #define ls(p) p<<1
  4 #define rs(p) p<<1|1
  5 const int N = 100010;
  6 typedef long long ll;
  7 int tag[N] , length[N][3];
  8 int xx[N] , zz[N];
  9 struct ScanLine{
 10     int y;
 11     int right_x,left_x;
 12     int inout;
 13     ScanLine(){}
 14     ScanLine(int y,int x2,int x1,int io):
 15     y(y) , right_x(x2) , left_x(x1) , inout(io){}
 16 }line[N];
 17 struct data{
 18     int x1,x2,y1,y2,z1,z2;
 19 }cube[N];
 20 bool cmp(ScanLine a , ScanLine b){ return a.y<b.y; }
 21 void push_up(int p , int pl , int pr){
 22     if(tag[p] > 2){
 23         length[p][2] = xx[pr]-xx[pl];
 24         length[p][0] = length[p][1] = 0;
 25         return ;
 26     }
 27     else if(tag[p] == 2){
 28         if(pl+1==pr){
 29             length[p][1] = xx[pr]-xx[pl];
 30             length[p][2] = length[p][0] = 0;
 31             return ;
 32         }else{
 33             length[p][2] = length[ls(p)][2]+length[rs(p)][2]+length[ls(p)][1]+length[rs(p)][1]+length[ls(p)][0]+length[rs(p)][0];
 34             length[p][1] = xx[pr]-xx[pl]-length[p][2];
 35             length[p][0] = 0;
 36         }
 37     }
 38     else if(tag[p] == 1){
 39         if(pl+1==pr){
 40             length[p][0] = xx[pr]-xx[pl];
 41             length[p][1]=length[p][2]=0;
 42             return ;
 43         }
 44         else{
 45             length[p][2] = length[ls(p)][2]+length[rs(p)][2]+length[ls(p)][1]+length[rs(p)][1];
 46             length[p][1] = length[ls(p)][0]+length[rs(p)][0];
 47             length[p][0] = xx[pr]-xx[pl]-length[p][1]-length[p][2];
 48         }
 49     }
 50     else{
 51         if(pl+1 == pr){
 52             length[p][0]=length[p][1]=length[p][2]=0;
 53             return ;
 54         }
 55         length[p][2] = length[ls(p)][2]+length[rs(p)][2];
 56         length[p][1] = length[ls(p)][1]+length[rs(p)][1];
 57         length[p][0] = length[ls(p)][0]+length[rs(p)][0];
 58     }
 59 }
 60 void update(int L, int R , int io,int p , int pl ,int pr){
 61     if(L <= pl && pr <= R){
 62         tag[p] += io;
 63         push_up(p,pl,pr);
 64         return ;
 65     }
 66     if(pl+1 == pr) return ;
 67     int mid = pl+pr >> 1;
 68     if(L <= mid) update(L,R,io,ls(p),pl,mid);
 69     if(R > mid)  update(L,R,io,rs(p),mid,pr);
 70     push_up(p,pl,pr);
 71 }
 72 int main()
 73 {
 74     int t,n,cnt1=0;
 75     scanf("%d",&t);
 76     while(t--){
 77         scanf("%d",&n);
 78         ll ans=0;
 79         int cntx=0 , cntz=0;
 80         for(int i = 1; i <= n; i++){
 81             scanf("%d%d%d%d%d%d",&cube[i].x1,&cube[i].y1,&cube[i].z1,&cube[i].x2,&cube[i].y2,&cube[i].z2);
 82             xx[++cntx] = cube[i].x1;
 83             zz[++cntz] = cube[i].z1;
 84             xx[++cntx] = cube[i].x2;
 85             zz[++cntz] = cube[i].z2;
 86         }
 87         if(n<3){
 88             printf("Case %d: 0\n",++cnt1);
 89             continue;
 90         }
 91         sort(xx+1,xx+1+cntx);
 92         sort(zz+1,zz+1+cntz);
 93         cntx = unique(xx+1,xx+1+cntx)-(xx+1);
 94         cntz = unique(zz+1,zz+1+cntz)-(zz+1);
 95         for(int i = 1; i < cntz; i++){
 96             int tot=0;
 97             for(int j = 1; j <= n; j++){
 98                 if(cube[j].z1 <= zz[i] && zz[i] < cube[j].z2){
 99                     line[++tot].y = cube[j].y1;  line[tot].right_x=cube[j].x2; line[tot].left_x=cube[j].x1; line[tot].inout=1;
100                     line[++tot].y = cube[j].y2;  line[tot].right_x=cube[j].x2; line[tot].left_x=cube[j].x1; line[tot].inout=-1;
101                 }
102             }
103             memset(length,0,sizeof(length));
104             memset(tag,0,sizeof(tag));
105             sort(line+1,line+1+tot,cmp);
106             ll s=0;
107             for(int j = 1; j <= tot; j++){
108                 int L,R;
109                 s += 1ll*length[1][2]*(line[j].y-line[j-1].y);
110                 R = lower_bound(xx+1,xx+1+cntx,line[j].right_x)-xx;
111                 L = lower_bound(xx+1,xx+1+cntx,line[j].left_x)-xx;
112                 update(L,R,line[j].inout,1,1,cntx);
113             }
114             ans += s*(zz[i+1]-zz[i]);
115         }
116         printf("Case %d: %lld\n",++cnt1,ans);
117     }
118     return 0;
119 }

所谓无底深渊,下去,也算是前程万丈

文章到此结束,我们下次再见

标签:pr,重叠,rs,xx,length,体积,ls,立方,pl
From: https://www.cnblogs.com/smiling-weeping-zhr/p/17653364.html

相关文章

  • C# 判断两个时间区间是否交叉重叠 (Determine Whether Two Date Ranges Overlap)
    给定两个日期间隔A和B,组件.start和.end和约束.start<=.end,如果:A.end>=B.startANDA.start<=B.end您可以调整>=与>和<=与<的使用,以满足您对重叠程度的要求。举例:该要求是如果StartDate=EndDate不算重合if(A.EndDate>B.StartDate&&A.StartDate<B.EndDate){......
  • 【LeetCode2118. 建立方程】 group_concat指定分隔符,指定排序顺序
    目录题目地址题目描述代码题目地址https://leetcode.cn/problems/build-the-equation/description/题目描述Example2:输入:Terms表:+-------+--------+|power|factor|+-------+--------+|4|-4||2|1||1|-1|+-------+---......
  • Luogu P9510 『STA - R3』高维立方体 题解
    题目传送门没见过这玩意,写个题解记下。题目大意周知斐波那契数列定义为:\[\operatorname{fib}(n)=\left\{\begin{aligned}1&&n\le2\\\operatorname{fib}(n-1)+\operatorname{fib}(n-2)&&n>2\end{aligned}\right.\]然后定义(\(n\le0\)函数值为\(0\))\[f(n)......
  • 2023-08-12:用go语言写算法。实验室需要配制一种溶液,现在研究员面前有n种该物质的溶液,
    2023-08-12:用go语言写算法。实验室需要配制一种溶液,现在研究员面前有n种该物质的溶液,每一种有无限多瓶,第i种的溶液体积为v[i],里面含有w[i]单位的该物质,研究员每次可以选择一瓶溶液,将其倒入另外一瓶(假设瓶子的容量无限),即可以看作将两个瓶子内的溶液合并,此时合并的溶液体积和物质含量......
  • 遥遥领先 spring,中国人的 solon 来啦!10% 的体积,10倍的速度
    Solon是什么?Java生态型应用开发框架。它从零开始构建,有自己的标准规范与开放生态(历时五年,已有全球第二级别的生态规模)。与其他框架相比,它解决了两个重要的痛点:启动慢,费内存。2023年6月,Maven单月下载量突破200万。解决痛点?由于Solon Bean容器的独特设计,不会因为扩展依赖变多......
  • 云立方HTTP代理推荐吗?不同类型代理适用的业务是什么?
    随着互联网大数据的应用,HTTP代理也逐渐被大家所熟知应用,HTTP代理服务商也层出不穷,用了这许多年的HTTP代理,很容易就发现这个问题:大家对HTTP代理产品各种名称没有一个统一的标准,想买个代理,很容易就出现以下情况:请问要如何从以上分辨出HTTP代理产品的类型,并且以此来判断是否符合自己业......
  • 论文解读|进一步融合:体积融合中6D姿态估计的多对象推理
    原创|文BFT机器人01背景机器人等智能设备需要从它们的车载视觉系统中获得高效的基于物体的场景表示,以解释接触、物理和遮挡。已识别的精确对象模型将与未识别结构的非参数重建一起发挥重要作用。本文提出了一个系统用于估计实时的接触和遮挡的精确姿态。从单个RGBD视图中提出三......
  • 直播网站源码,RecycleView实现item重叠水平滑动
    直播网站源码,RecycleView实现item重叠水平滑动装饰器第一个item不偏移,其他item向左偏移一定距离,代码为:mRecyclerView.addItemDecoration(newRecyclerView.ItemDecoration(){  @Override  publicvoidgetItemOffsets(RectoutRect,Viewview,RecyclerViewparent,......
  • HJ107 求解立方根
    1.题目读题HJ107 求解立方根  考查点 2.解法思路 解题思路:我们可以使用二分法来求解立方根,即在一个区间内不断缩小范围,直到找到一个满足条件的数。首先,我们确定一个初始区间[0,N],然后计算区间的中点mid=(0+N)/2,判断mid的立方是否等于N,如果等于,则直接返......
  • 案例 1 , 旋转立方体
    <script>//创建场景varscene=newTHREE.Scene();//设置相机(视野,显示口的宽高比,近裁剪面,远裁剪面)varcamera=newTHREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000);//渲染器varrenderer=newTHREE.WebGLRen......