1#include <cstdio>2#include <algorithm>3#include <map>4#include <cstring>5#include <queue>6 using namespacestd;7 inta[ the][ the][ the],x_map[ the],y_map[ the],z_map[ the],8x1_ori[ the],y1_ori[ -],z1_ori[ -],x2_ori[ -],y2_ori[ -],z2_ori[ -],9x_move[6]={1,-1,0,0,0,0},y_move[6]={0,0,1,-1,0,0},z_move[6]={0,0,0,0,1,-1},Ten x_cnt,y_cnt,z_cnt; One Long LongAns_s,ans_v; Amap<int,int>X_rev,y_rev,z_rev; - structCond - { the intx, y, z - }c1,c2; -Queue<cond>Q; - intMain () + { - inti,j,k,l,m,n,p,x,y,z,t,xx,yy,zz,temp; +scanf"%d",&t); A while(t--) at { -Memset (A,0,sizeof(a)); -memset (X_map,0,sizeof(X_map)); -memset (Y_map,0,sizeof(Y_map)); -memset (Z_map,0,sizeof(Z_map)); -memset (X1_ori,0,sizeof(X1_ori)); inmemset (Y1_ori,0,sizeof(Y1_ori)); -memset (Z1_ori,0,sizeof(Z1_ori)); tomemset (X2_ori,0,sizeof(X2_ori)); +memset (Y2_ori,0,sizeof(Y2_ori)); -memset (Z2_ori,0,sizeof(Z2_ori)); the x_rev.clear (); * y_rev.clear (); $ z_rev.clear ();Panax Notoginsengscanf"%d",&n); - for(i=1; i<=n;i++) the { +scanf"%d%d%d%d%d%d",&x1_ori[i],&y1_ori[i],&z1_ori[i],&x,&y,&z); Ax_map[i]=X1_ori[i]; they_map[i]=Y1_ori[i]; +z_map[i]=Z1_ori[i]; -x_map[i+n]=x2_ori[i]=x1_ori[i]+x; $y_map[i+n]=y2_ori[i]=y1_ori[i]+y; $z_map[i+n]=z2_ori[i]=z1_ori[i]+Z; - } -Sort (x_map+1, x_map+2*n+1); theSort (y_map+1, y_map+2*n+1); -Sort (z_map+1, z_map+2*n+1);WuyiX_cnt=unique (x_map+1, x_map+2*n+1)-(x_map+1); theY_cnt=unique (y_map+1, y_map+2*n+1)-(y_map+1); -Z_cnt=unique (z_map+1, z_map+2*n+1)-(z_map+1); Wu for(i=1; i<=x_cnt;i++) -x_rev[x_map[i]]=i; About for(i=1; i<=y_cnt;i++) $y_rev[y_map[i]]=i; - for(i=1; i<=z_cnt;i++) -z_rev[z_map[i]]=i; The above is discretized -x_map[0]=y_map[0]=z_map[0]=0; Ax_map[x_cnt+1]=y_map[y_cnt+1]=z_map[z_cnt+1]=1005; boundary, you need to surround the air more than a circle outside. + for(i=1; i<=n;i++) the for(x=x_rev[x1_ori[i]];x<x_rev[x2_ori[i]];x++) - for(y=y_rev[y1_ori[i]];y<y_rev[y2_ori[i]];y++) $ for(z=z_rev[z1_ori[i]];z<z_rev[z2_ori[i]];z++) thea[x][y][z]=1; Fill theans_v=1005*1005*1005; theans_s=0; thec1.x=c1.y=c1.z=0; - Q.push (C1); ina[0][0][0]=2; 2 means you've been in the team. the while(!q.empty ()) the { Aboutc1=Q.front (); the Q.pop (); thexx=c1.x; theyy=c1.y; +zz=c1.z; -ans_v-= (x_map[xx+1]-X_MAP[XX]) * (y_map[yy+1]-Y_MAP[YY]) * (z_map[zz+1]-Z_map[zz]); the for(i=0; i<=5; i++)Bayi { thex=xx+X_move[i]; they=yy+Y_move[i]; -z=zz+Z_move[i]; - if(x>=0&&x<=x_cnt&&y>=0&&y<=y_cnt&&z>=0&&z<=z_cnt) the { the if(a[x][y][z]==0) the { thec2.x=x; -c2.y=y; thec2.z=Z; thea[x][y][z]=2; To mark the queue, it cannot be removed. the Q.push (C2);94 } the if(a[x][y][z]==1) the { thetemp=1;98 if(x==xx) temp*= (x_map[xx+1]-x_map[xx]); About if(Y==YY) temp*= (y_map[yy+1]-Y_map[yy]); - if(Z==ZZ) temp*= (z_map[zz+1]-Z_map[zz]);101ans_s+=temp; Calculation Area102 }103 }104 } the }106printf"%lld%lld\n", Ans_s,ans_v);107 }108}
Discretization of the +floodfill.
The first use of DFS results in re-thinking may be a stack overflow, instead of BFS after AC.
As the volume and area are seen from the outside, you can start FloodFill from the outside circle of "air", each time you encounter a sculpture with surface area, because each surface area will and only with a piece of air contact. Volume with total volume minus the volume of air encountered.
Because of the large coordinates, discretization is required.
UVA 12171 sculpture (Super good title)--yhx