AOAPC The Sixth chapter R question sculpture

Source: Internet
Author: User

AOAPC The Sixth chapter R question sculpture

Http://7xjob4.com1.z0.glb.clouddn.com/5e3271c0195996a70363138f9cb82dd5

Imagine a box, made of copper plate. Imagine a second one, intersecting the RST one, and several others, intersecting each other (or not). That's how the sculptor Oto Boxing constructs his sculptures. In fact he does not construct that much, he is only makes the design; The actual construction is contracted out to a construction company. For the calculation of the costs of construction, the company needs to know the total area of copper plate involved. Parts of a box that is hidden in another box is not realized in copper, of course. (Copper is quite expensive, and prices is rising.) After construction, the total construction are plunged into a bath of chemicals. To prevent the "bath from running", the construction company wants to know the total volume of the construction. Given that a construction was a collection of boxes, you were asked to calculate the area and the volume of the construction . Some of Oto ' s designs are connected, others is not. Either, we want to know the totAl area and the total volume. It might happen that the boxes completely enclose space that's not included in any of the boxes (see the second example B Elow). Because The liquid cannot enter that space, its volume must is added to the total volume. Copper plate bordering this space was superfluous, of course, so it does not add to the area.

Input

The RST line one positive number:the number of testcases, at most 100. After this per testcase: one line with an integer n (1≤n≤50): The number of boxes involved. • N lines with six positive integers x0, y0, z0,x, Y, Z (1≤x0, y0, z0, X, Y, z≤500): The Triple (x0, y0, z0) are the V Ertex of the box with the minimum values for the coordinates and the numbers x, Y, Z is the dimensions of the box (x, y a nd z dimension, respectively). All dimensions is in centimeters. The sides of the boxes is always parallel to the coordinate axes.

Output

Per testcase:

one line with both numbers separated by single spaces:the total amount of copper plate needed (in cm2), and the total V Olume (in cm3).

Sample Input

2

2

1 2 3 3 4 5

6 2 3 3 4 5

7

1 1 1 5 5 1

1 1 10 5 5 1

1 1 2 1 4 8

2 1 2 4 1 8

5 2 2 1 4 8

1 5 2 4 1 8

3 3 4 1 1 1

Sample Output

188 120

250 250

Discrete +fullfill, note that DFS may explode stacks, preferably with BFS.

#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<queue>#defineREP (I,A,B) for (int i=a;i<=b;i++)#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;Const intmaxn= -;Const intInf= (1<< in);intN;intX[MAXN],Y[MAXN],Z[MAXN];intXn,yn,zn;BOOLVIS[MAXN][MAXN][MAXN];BOOLBOX[MAXN][MAXN][MAXN];structnode{intx0,y0,z0; intx, Y, Z intx1,y1,z1; voidRead () {scanf ("%d%d%d%d%d%d",&x0,&y0,&z0,&x,&y,&z); X1=x0+x;y1=y0+y;z1=z0+Z; x[++xn]=x0; x[++xn]=X1; y[++yn]=y0; y[++yn]=Y1; z[++zn]=z0; z[++zn]=Z1; }}; Node p[maxn];ll v,s;intdx[]={-1,1,0,0,0,0};intdy[]={0,0,-1,1,0,0};intdz[]={0,0,0,0,-1,1};ll Volume (intXintYintz) {ll a=x[x+1]-x[x],b=y[y+1]-y[y],c=z[z+1]-Z[z]; returna*b*C;} ll area (intOpintIintj) {    if(op==1) {ll a=y[i+1]-y[i],b=z[j+1]-Z[j]; returnA *b; }    if(op==2) {ll a=z[i+1]-z[i],b=x[j+1]-X[j]; returnA *b; }    if(op==3) {ll a=x[i+1]-x[i],b=y[j+1]-Y[j]; returnA *b; }}structqnode{intx, Y, z;};voidBFs () {MS0 (VIS); Queue<qNode>Q; Q.push ({1,1,1}); vis[1][1][1]=1;  while(!Q.empty ()) {qnode U=Q.front (); Q.pop (); V+=volume (U.X,U.Y,U.Z); REP (i,0,5){            intnx=u.x+dx[i],ny=u.y+dy[i],nz=u.z+Dz[i]; if(nx<1|| nx>=xn| | ny<1|| ny>=yn| | nz<1|| NZ&GT;=ZN)Continue; if(Vis[nx][ny][nz])Continue; if(!box[nx][ny][nz]) Q.push ({nx,ny,nz}), vis[nx][ny][nz]=1; Else{                if(U.X!=NX) S+=area (1, NY,NZ); if(U.y!=ny) S+=area (2, NZ,NX); if(U.Z!=NZ) S+=area (3, Nx,ny); }            //cout<< "x=" <<u.x<< "y=" <<u.y<< "z=" <<u.z<< "nx=" <<nx<< " Ny= "<<ny<<" nz= "<<nz<<" box= "<<box[nx][ny][nz]<<endl;        }    }}voidDfsintXintYintz) {    if(Vis[x][y][z])return; VIS[X][Y][Z]=1; V+=volume (x, y, z); REP (i,0,5){        intnx=x+dx[i],ny=y+dy[i],nz=z+Dz[i]; if(nx<1|| nx>=xn| | ny<1|| ny>=yn| | nz<1|| NZ&GT;=ZN)Continue; if(!Box[nx][ny][nz]) DFS (NX,NY,NZ); Else{            if(X!=NX) S+=area (1, y,z); if(Y!=ny) S+=area (2, z,x); if(Z!=NZ) S+=area (3, x, y); }    }}voidDebug () {cout<<Xn<<Endl; REP (i,1, Xn) cout<<x[i]<<" ";cout<<Endl;}intMain () {Freopen ("In.txt","R", stdin); intT;cin>>u;  while(t--) {Xn=yn=zn=0; x[++xn]=0; x[++xn]=3010; y[++yn]=0; y[++yn]=3010; z[++zn]=0; z[++zn]=3010; scanf ("%d",&N); REP (i,1, N) p[i].read (); Sort (X+1, x+xn+1); Sort (Y+1, y+yn+1); Sort (Z+1, z+zn+1); Xn=unique (x+1, x+xn+1)-(x+1); Yn=unique (y+1, y+yn+1)-(y+1); Zn=unique (z+1, z+zn+1)-(z+1); //debug ();MS0 (box); REP (i,1, N) {            intX0=lower_bound (x+1, x+xn+1, p[i].x0)-x,x1=lower_bound (x+1, x+xn+1, p[i].x1)-X; intY0=lower_bound (y+1, y+yn+1, p[i].y0)-y,y1=lower_bound (y+1, y+yn+1, P[i].y1)-x; intZ0=lower_bound (z+1, z+zn+1, p[i].z0)-z,z1=lower_bound (z+1, z+zn+1, P[I].Z1)-Z; REP (i,x0,x1-1) {REP (j,y0,y1-1) {REP (k,z0,z1-1) {Box[i][j][k]=1;        }}}} MS0 (VIS); V=s=0; //DFS (1,1,1);BFS (); printf ("%lld%lld\n", s,3010ll*3010*3010-V); }    return 0;}
View Code

AOAPC The Sixth chapter R question sculpture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.