[SDOI2008] Cube overlay-rectangular cut (cube cut)

Source: Internet
Author: User
Title Description

A June recently for the preparation of the provincial team selection, specially for the data structure of the special training. In the course of training, we encounter the classical problem of "rectangular area and", that is, to give the rectangle of n each side and the axis parallel (perpendicular), and find the sum of the area covered by the rectangle. A June according to the vertical axis to establish a line tree after the scanning calculation, easy to ac this problem, the time complexity of O (Nlogn).
In order to strengthen the training, a June will extend the problem to three-dimensional space, that is: Give the n each edge and axis parallel (vertical) cube, to find the sum of the volume of the cube cover. To simplify the problem, the cube is degraded to a positive cube, with a four-tuple (x, Y, Z, R) representing a cube, where x, Y, Z are the center point coordinates of the cube, and R is the distance from the center point to each polygon of the cube (that is, half the height of the cube).
This time can be stumped a June, had to ask you-the future gold medal-to help him. Input Format

The first line is a positive integer n.
The following n lines are four integers per line x, Y, Z, R, separated by a space. output Format

A total of one number, that is, the total product of coverage. Sample Data Sample Input

3
0 0 0 3
1–1 0 1
3 5 6 sample Output

1944 data size and conventions

For 30% of data, 1≤n≤5
For 70% of data, 1≤n≤30
For 100% of data, 1≤n≤100
For 100% data, -1000≤x, y, z≤1000,1≤r≤200 topic analysis

With a NOI97 satellite covering a dime.
The students in that session can actually get the gold medal. Source Code

#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include < cstdlib> #include <vector> #include <cstdio> #include <cmath> #include <queue> using
namespace Std;
    inline const int Get_int () {int num=0,bj=1;
    Char X=getchar (); while (x< ' 0 ' | |
        X> ' 9 ') {if (x== '-') bj=-1;
    X=getchar ();
        } while (x>= ' 0 ' &&x<= ' 9 ') {num=num*10+x-' 0 ';
    X=getchar ();
} return NUM*BJ;
} const int maxn=3;
struct Cube {double left[maxn],right[maxn];};
    struct Universal_cut {Cube a[10005];
    int sum;
    int init () {sum=0; } bool If_intersect (Cube A,cube b) {for (int i=0; i<maxn; i++) if (a.left[i]>=b.right[i]| |
        A.right[i]<=b.left[i]) return false;
    return true; 
        } void Add (double x[maxn],double y[maxn]) {sum++; 
            for (int i=0; i<maxn; i++) {a[sum].left[i]=x[i]; A[Sum].right[i]=y[i];
        }} void del (int index) {a[index]=a[sum];
    sum--;
        } void Cut (Cube a,cube b,int dimension) {//Return intersection if (DIMENSION==MAXN) return;
        Double K1=max (a.left[dimension],b.left[dimension]);
        Double K2=min (a.right[dimension],b.right[dimension]);
            if (A.LEFT[DIMENSION]&LT;K1) {Cube tmp=a;
            TMP.RIGHT[DIMENSION]=K1;
        Add (tmp.left,tmp.right);
            } if (K2<a.right[dimension]) {Cube tmp=a;
            TMP.LEFT[DIMENSION]=K2;
        Add (tmp.left,tmp.right);
        } a.left[dimension]=k1;
        A.RIGHT[DIMENSION]=K2;
    Cut (a,b,dimension+1);
}
};
Universal_cut C;
int n,ans=0;
Double BLEFT[MAXN],BRIGHT[MAXN];
    int main () {n=get_int ();
        for (int i=1; i<=n; i++) {int x=get_int (), Y=get_int (), Z=get_int (), H=get_int ();
        Bleft[0]=x-h,bleft[1]=y-h,bleft[2]=z-h,bright[0]=x+h,bright[1]=y+h,bright[2]=z+h; Cube b;
            for (int i=0; i<maxn; i++) {b.left[i]=bleft[i];
        B.right[i]=bright[i];
            } for (int j=1; j<=c.sum; J + +) {if (!c.if_intersect (c.a[j],b)) continue;
            C.cut (c.a[j],b,0);
            C.del (j);
        j--;
    } c.add (Bleft,bright);
        } for (int i=1; i<=c.sum; i++) {int tmp=1;
        for (int j=0; j<maxn; j + +) Tmp*=c.a[i].right[j]-c.a[i].left[j];
    ans+=tmp;
    } printf ("%d\n", ans);
return 0; }

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.