• aoapc第六章 R题 Sculpture


    aoapc第六章 R题 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 is how the sculptor Oto Boxing constructs his sculptures. In fact he does not construct that much, he 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 are hidden in another box are not realized in copper, of course. (Copper is quite expensive, and prices are rising.) After construction, the total construction is plunged into a bath of chemicals. To prevent this bath from running over, the construction company wants to know the total volume of the construction. Given that a construction is a collection of boxes, you are asked to calculate the area and the volume of the construction. Some of Oto’s designs are connected, others are not. Either way, we want to know the total area and the total volume. It might happen that the boxes completely enclose space that is not included in any of the boxes (see the second example below). Because the liquid cannot enter that space, its volume must be added to the total volume. Copper plate bordering this space is superfluous, of course, so it does not add to the area.

    Input

    On the rst line one positive number: the number of testcases, at most 100. After that 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) is the vertex of the box with the minimum values for the coordinates and the numbers x, y, z are the dimensions of the box (x, y and z dimension, respectively). All dimensions are in centimeters. The sides of the boxes are always parallel to the coordinate axes.

    Output

    Per testcase:

    • One line with two numbers separated by single spaces: the total amount of copper plate needed (in cm2 ), and the total volume (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

    离散化+fullfill,注意dfs可能会爆栈,最好用bfs。

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #define REP(i,a,b) for(int i=a;i<=b;i++)
    #define MS0(a) memset(a,0,sizeof(a))
    
    using namespace std;
    
    typedef long long ll;
    const int maxn=120;
    const int INF=(1<<29);
    
    int n;
    int X[maxn],Y[maxn],Z[maxn];
    int Xn,Yn,Zn;
    bool vis[maxn][maxn][maxn];
    bool box[maxn][maxn][maxn];
    struct Node
    {
        int x0,y0,z0;
        int x,y,z;
        int x1,y1,z1;
        void read()
        {
            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;
    int dx[]={-1,1,0,0,0,0};
    int dy[]={0,0,-1,1,0,0};
    int dz[]={0,0,0,0,-1,1};
    
    ll volume(int x,int y,int z)
    {
        ll a=X[x+1]-X[x],b=Y[y+1]-Y[y],c=Z[z+1]-Z[z];
        return a*b*c;
    }
    
    ll area(int op,int i,int j)
    {
        if(op==1){
            ll a=Y[i+1]-Y[i],b=Z[j+1]-Z[j];
            return a*b;
        }
        if(op==2){
            ll a=Z[i+1]-Z[i],b=X[j+1]-X[j];
            return a*b;
        }
        if(op==3){
            ll a=X[i+1]-X[i],b=Y[j+1]-Y[j];
            return a*b;
        }
    }
    
    struct qNode
    {
        int x,y,z;
    };
    
    void bfs()
    {
        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){
                int nx=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>=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;
            }
        }
    }
    
    void dfs(int x,int y,int z)
    {
        if(vis[x][y][z]) return;
        vis[x][y][z]=1;
        V+=volume(x,y,z);
        REP(i,0,5){
            int nx=x+dx[i],ny=y+dy[i],nz=z+dz[i];
            if(nx<1||nx>=Xn||ny<1||ny>=Yn||nz<1||nz>=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);
            }
        }
    }
    
    void debug()
    {
        cout<<Xn<<endl;
        REP(i,1,Xn) cout<<X[i]<<" ";cout<<endl;
    }
    
    int main()
    {
        freopen("in.txt","r",stdin);
        int T;cin>>T;
        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){
                int x0=lower_bound(X+1,X+Xn+1,p[i].x0)-X,x1=lower_bound(X+1,X+Xn+1,p[i].x1)-X;
                int y0=lower_bound(Y+1,Y+Yn+1,p[i].y0)-Y,y1=lower_bound(Y+1,Y+Yn+1,p[i].y1)-Y;
                int z0=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
    ",S,3010LL*3010*3010-V);
        }
        return 0;
    }
    View Code
    没有AC不了的题,只有不努力的ACMER!
  • 相关阅读:
    今天去一个物流公司參观的一些体会
    Yii学习笔记之四(表单验证 api 翻译)
    IT忍者神龟之Hibernat持久化对象-数据表映射配置回想
    LeetCode:Unique Binary Search Trees
    nodejs版本号更新问题:express不是内部或外部命令
    让Apache 和nginx支持跨域訪问
    聊聊高并发(十六)实现一个简单的可重入锁
    【iOS】自己定义TabBarController
    《互联网医疗大棋局》中美移动医疗领域的现状、机会、限制。五星推荐
    《无穷的开始:世界进步的本源》量子物理学家的哲学思考。三星推荐
  • 原文地址:https://www.cnblogs.com/--560/p/4894297.html
Copyright © 2020-2023  润新知