light oj 1211 - Intersection of Cubes (立方体的交集的体积)

    xiaoxiao2022-08-11  37

    1211 - Intersection of Cubes    PDF (English)StatisticsForum Time Limit: 0.5 second(s)Memory Limit: 32 MB

    You are given n cubes, each cube is described by two points in 3D space: (x1, y1, z1) being one corner of the cube and (x2, y2, z2) being the opposite corner. Assume that the sides of each of the cubes are parallel to the axis. Your task is to find the volume of their intersection.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing an integer n (1 ≤ n ≤ 100). Each of the next n lines contains six integers x1 y1 z1 x2 y2 z2 (1 ≤ x1, y1, z1, x2, y2, z2 ≤ 1000, x1 < x2, y1 < y2, z1 < z2) where (x1, y1, z1) is the co-ordinate of one corner and (x2, y2, z2) is the co-ordinate of the opposite corner.

    Output

    For each case, print the case number and volume of their intersection.

    Sample Input

    Output for Sample Input

    2

    2

    1 1 1 3 3 3

    1 1 1 2 2 2

    3

    7 8 9 20 20 30

    2 2 2 50 50 50

    13 14 15 18 30 40

    Case 1: 1

    Case 2: 450

     

    解:已知每组数的立方体的左下角和右上角的坐标,要求交集,就求左下角的各个坐标最大值,右上角的各个坐标的最小值,然后判断是否所得的最小值都大于最大值,然后求体积即可 代码: #include <iostream> #include <cstdio> #include <cmath> #define LL long long using namespace std; struct Node { LL x1,y1,z1; LL x2,y2,z2; }; Node node[110]; int main() { int t,k=1,n; scanf("%d",&t); while(t--) { LL xmax=0,xmin=1100,ymax=0,ymin=1100,zmax=0,zmin=1100; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%lld%lld%lld%lld%lld%lld",&node[i].x1,&node[i].y1,&node[i].z1,&node[i].x2,&node[i].y2,&node[i].z2); xmax=max(xmax,node[i].x1); ymax=max(ymax,node[i].y1); zmax=max(zmax,node[i].z1); xmin=min(xmin,node[i].x2); ymin=min(ymin,node[i].y2); zmin=min(zmin,node[i].z2); } long long v; if(zmin>zmax && ymin>ymax && xmin>xmax)//注意条件 v=(zmin-zmax)*(ymin-ymax)*(xmin-xmax); else v=0; printf("Case %d: %lld\n",k++,v); } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1132666.html
    最新回复(0)