poj 1022 Packing Unit 4D Cubes

5 篇文章 0 订阅

Packing Unit 4D Cubes
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 2281
Accepted: 758

Description




We usually think that there are three geometric dimensions; the fourth dimension is usually time. However, the Association for Customizing Machines (ACM) has to deal with four geometrical dimensions for their strange customer EE3 who needs to pack four dimensional products into perpendicular parallelepipeds before shipping them to the newly emerged market niche just on the outskirts of the Milky Way. 
Each of EE3 products consists of a number of unit 4D cubes that are glued together at their faces. A face of a 4D cube is a 3D cube and each 4D cube has 8 such faces. The picture on the left shows a 4D cube projected into a plane with the four principal, orthogonal axes shown. It takes a bit of effort to stretch our imagination and see the faces of a 4D cube in such a projection. The pictures below try to illustrate how the two faces along each of the four axes are situated in 4D. Again, using just the planar projection it is not so easy to illustrate and takes some effort to see. But we have done a good job, didn't we? 


 
Each EE3 product to be packed consists of a number of unit 4D cubes that are glued together along their faces which are 3D cubes. Your job is simple: find the minimal volume measured in the number of unit 4D cubes of a perpendicular parallelepiped (a 4D box) into which the product can be packed before shipping.

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by input data for each test case describing one EE3 product. The first line of each test case is an integer n (1 ≤ n ≤ 100) which is the number of unit 4D cubes used in the product. Next, there are n lines, each describing one unit cube and contains 9 nonnegative integer numbers. 
The first number, a positive integer, is the unique identifier of a cube and the remaining 8 numbers give the identities of neighbors of the cube listed in the following order: 
?the first two numbers are identifiers of the cubes glued to the opposing sides of the given cube along the x1 axis as seen looking in the direction of the x1 axis; 
?the next two numbers as above but for the x2 axis; 
?the next two numbers as above but for the x3 axis; 
?the next two numbers as above but for the x4 axis; 
If a cube does not have a neighbor glued to one of its faces we use 0 instead of a cube identifier. 
The problem is that the employees of ACM may produce inconsistent descriptions of EE3 products. There are two sources of such inconsistencies: 
?A consistent description must be symmetric, i.e. if cube x is glued to cube y at some face then cube y must be glued to cube x at the corresponding face along the same axis. The following description is inconsistent: 
3 0 0 1 0 0 0 0 0 
1 0 0 3 0 0 0 0 0 
?Any description must describe a single solid, i.e. there must be only one component in the product. Thus the following is inconsistent: 
1 2 0 0 0 0 0 0 0 
2 0 1 0 0 0 0 0 0 
3 0 0 4 0 0 0 0 0 
4 0 0 0 3 0 0 0 0

Output

There should be one output line per test case containing either the number of unit 4D cubes in the smallest 4D perpendicular parallelepiped oriented along the axes into which the product can be packed if the description is consistent, or the word Inconsistent, otherwise.

Sample Input

1
9
1 2 3 4 5 6 7 8 9
2 0 1 0 0 0 0 0 0
3 1 0 0 0 0 0 0 0
4 0 0 0 1 0 0 0 0
5 0 0 1 0 0 0 0 0
6 0 0 0 0 0 1 0 0
7 0 0 0 0 1 0 0 0
8 0 0 0 0 0 0 0 1
9 0 0 0 0 0 0 1 0

Sample Output

81

这题主要是题目太长比较难懂==看了快一个小时才明白什么意思。。具体写起来还好

大致题意(这里由于个人表达能力较差参考了下别人的表达http://www.2cto.com/kf/201209/153339.html,并根据自己的理解做了补充和修改):有个4D的物体(有四个轴线方向类似三维有三个轴线方向),它在每个轴线方向有2个面(它的面就是三维的。。一共就有八个面),然后有n个这样的物体,用胶水把它们对应的面粘起来,组成一个组合体(可以这么叫吧。。)求能装下这个组合体的容器(也是4D的)的最小体积。输入数据的第1行有一个数n,表示有n个样例接下来每个样例的第一行是m,表示有m个这样的单位物体共同组成组合体接下来有m行,每一行有九个数,第一个数是该单位物体的编号,后面8个数分别指的是8个面是否有用胶水粘以及和哪个物体粘。

思路:类比三维的,体积就是每个轴方向的长度相乘然后就是要统计每个轴方向有几个单位长度(有几个这样的单位物体),dfs。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;

int flag,t,cnt,vis[105],a[105][8],sum1,sum2,sum3,sum4,pre;
map<int,int> mp1;//从编号到下标的映射(这个是看到网上别人用了map就用了==本来没想到这个的)
map<int,int> mp2;//从下标到编号的映射

void dfs(int i)
{
    int j;
    if(flag)return;
    if(vis[i])return;
    if(t!=8&&a[i][t]!=pre){flag=1;return;}
    vis[i]=1;
    cnt++;
    for(j=0;j<8;j++)
    {
        if(flag)break;
        if(a[i][j]!=0)
        {
            if(j%2==0)t=j+1;
            else t=j-1;
            if(j==1||j==0)sum1++;//统计面数
            else if(j==2||j==3)sum2++;
            else if(j==4||j==5)sum3++;
            else if(j==6||j==7)sum4++;
            pre=mp2[i];
            dfs(mp1[a[i][j]]);
        }
    }
}

int main()
{
    int T,n,p,num,q;
    scanf("%d",&T);
    while(T--)
    {
        sum1=sum2=sum3=sum4=0;
        flag=0;
        t=8;
        cnt=0;//这个地方和下面一行当初没更新==WA了。。以后调试的时候如果有输入多组数据可以试着把同一组数据输两次看看结果一不一样
        memset(vis,0,sizeof(vis));
        scanf("%d",&n);
        for(p=0;p<n;p++)
        {
            scanf("%d",&num);
            mp1[num]=p;
            mp2[p]=num;
            for(q=0;q<8;q++)scanf("%d",&a[p][q]);
        }
        dfs(0);
        if(flag||cnt<n)printf("Inconsistent\n");
        else printf("%d\n",(sum1/2+1)*(sum2/2+1)*(sum3/2+1)*(sum4/2+1));
    }
    return 0;
}























  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值