POJ1022 Packing Unit 4D Cubes
题目来源:http://poj.org/problem?id=1022
题目大意:
有一些4维的单位体积的立方体盒子,每个立方体有8个面。要用一个大的4为盒子将它们包起来,求最小的大盒子体积。
输入:第一行为测试用例数。每个用例的第一行为单位立方体数目n。接下来的n行每行为一个立方体的信息。每行第一个数字为还立方体的编号,接下来的8个整数分别为对应面相邻的立方体的编号。该面没有邻居则为0.(给出的都是单一刚体。)
输出:最小的能把这个由小4D立方体拼起来的形状的盒子的体积。
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
本题题干描述得很复杂,想象起来也有一些抽象,其实很简单,跟3D的情况联系起来想就可以了。3D求包围盒的方法推广至4D即可。
- //////////////////////////////////////////////////////////////////////////
- // POJ1022 Packing Unit 4D Cubes
- // Memory: 300K Time: 16MS
- // Language: C++ Result: Accepted
- //////////////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- class Cube {
- public:
- int x1p, x1n, x2p, x2n, x3p, x3n, x4p, x4n;
- };
- class Pos {
- public:
- int id;
- int x1, x2, x3, x4;
- };
- int main() {
- int ncase;
- cin >> ncase;
- for (int caseNo = ; caseNo <= ncase; ++caseNo) {
- int n;
- map<int, Cube> cubes;
- cin >> n;
- for (int i = ; i <= n; ++i) {
- int id;
- cin >> id;
- Cube cube;
- cin >> cube.x1p >> cube.x1n >> cube.x2p >> cube.x2n
- >> cube.x3p >> cube.x3n >> cube.x4p >> cube.x4n;
- cubes[id] = cube;
- }
- bool ok = true;
- vector<Pos> solid;
- Pos firstPos;
- firstPos.id = (*cubes.begin()).first;
- firstPos.x1 = firstPos.x2 = firstPos.x3 = firstPos.x4 = ;
- solid.push_back(firstPos);
- for (map<int, Cube>::iterator itc = cubes.begin(); itc != cubes.end(); ++itc) {
- Cube cube1;
- int id = (*itc).first;
- int x1p = (*itc).second.x1p;
- //x1p
- if (x1p != ) {
- if (cubes[x1p].x1n != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x1p;
- pos.x1 = (*its).x1 + ;
- pos.x2 = (*its).x2;
- pos.x3 = (*its).x3;
- pos.x4 = (*its).x4;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x1p) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- //x1n
- int x1n = (*itc).second.x1n;
- if (x1n != ) {
- if (cubes[x1n].x1p != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x1n;
- pos.x1 = (*its).x1 - ;
- pos.x2 = (*its).x2;
- pos.x3 = (*its).x3;
- pos.x4 = (*its).x4;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x1n) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- //x2p
- int x2p = (*itc).second.x2p;
- if (x2p != ) {
- if (cubes[x2p].x2n != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x2p;
- pos.x1 = (*its).x1;
- pos.x2 = (*its).x2 + ;
- pos.x3 = (*its).x3;
- pos.x4 = (*its).x4;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x2p) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- //x2n
- int x2n = (*itc).second.x2n;
- if (x2n != ) {
- if (cubes[x2n].x2p != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x2n;
- pos.x1 = (*its).x1;
- pos.x2 = (*its).x2 - ;
- pos.x3 = (*its).x3;
- pos.x4 = (*its).x4;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x2n) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- //x3p
- int x3p = (*itc).second.x3p;
- if (x3p != ) {
- if (cubes[x3p].x3n != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x3p;
- pos.x1 = (*its).x1;
- pos.x2 = (*its).x2;
- pos.x3 = (*its).x3 + ;
- pos.x4 = (*its).x4;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x3p) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- //x3n
- int x3n = (*itc).second.x3n;;
- if (x3n != ) {
- if (cubes[x3n].x3p != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x3n;
- pos.x1 = (*its).x1;
- pos.x2 = (*its).x2;
- pos.x3 = (*its).x3 - ;
- pos.x4 = (*its).x4;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x3n) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- //x4p
- int x4p = (*itc).second.x4p;
- if (x4p != ) {
- if (cubes[x4p].x4n != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x4p;
- pos.x1 = (*its).x1;
- pos.x2 = (*its).x2;
- pos.x3 = (*its).x3;
- pos.x4 = (*its).x4 + ;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x4p) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- //x4n
- int x4n = (*itc).second.x4n;
- if (x4n != ) {
- if (cubes[x4n].x4p != id) {
- ok = false;
- break;
- }
- bool f = true;
- Pos pos;
- for (vector<Pos>::iterator its = solid.begin(); its != solid.end(); ++its) {
- if (f == false) break;
- if ((*its).id == id) {
- pos.id = x4n;
- pos.x1 = (*its).x1;
- pos.x2 = (*its).x2;
- pos.x3 = (*its).x3;
- pos.x4 = (*its).x4 - ;
- for (vector<Pos>::iterator itr = solid.begin(); itr != solid.end(); ++itr) {
- if ((*itr).id == x4n) {
- f = false;
- break;
- }
- }
- }
- }
- if (f == true) {
- solid.push_back(pos);
- }
- }
- }
- if (solid.size() != n) {
- ok = false;
- }
- if (ok == false) {
- cout << "Inconsistent" << endl;
- continue;
- }
- int x1min = ;
- int x1max = -;
- int x2min = ;
- int x2max = -;
- int x3min = ;
- int x3max = -;
- int x4min = ;
- int x4max = -;
- for (vector<Pos>::iterator it = solid.begin(); it != solid.end(); ++it) {
- if (x1min >(*it).x1) x1min = (*it).x1;
- if (x1max < (*it).x1) x1max = (*it).x1;
- if (x2min >(*it).x2) x2min = (*it).x2;
- if (x2max < (*it).x2) x2max = (*it).x2;
- if (x3min >(*it).x3) x3min = (*it).x3;
- if (x3max < (*it).x3) x3max = (*it).x3;
- if (x4min >(*it).x4) x4min = (*it).x4;
- if (x4max < (*it).x4) x4max = (*it).x4;
- }
- int vol = (x1max - x1min + ) * (x2max - x2min + ) * (x3max - x3min + ) * (x4max - x4min + );
- cout << vol << endl;
- }
- system("pause");
- return ;
- }
POJ1022 Packing Unit 4D Cubes的更多相关文章
- POJ题目排序的Java程序
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...
- Daily Query
-- GI Report SELECT A.PLPKLNBR, D.DNDNHNBR, F.DNSAPCPO, C.PPPRODTE, A.GNUPDDTE GI_DATE, B.INHLDCDE, ...
- 【Moqui业务逻辑翻译系列】Shipment Receiver Receives Shipment with Packing Slip but no PO
Shipment Receiver receives shipment. It has invoice tucked into it. Receiver records vendor name, ve ...
- ABP(现代ASP.NET样板开发框架)系列之12、ABP领域层——工作单元(Unit Of work)
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之12.ABP领域层——工作单元(Unit Of work) ABP是“ASP.NET Boilerplate Pr ...
- ABP源码分析十:Unit Of Work
ABP以AOP的方式实现UnitOfWork功能.通过UnitOfWorkRegistrar将UnitOfWorkInterceptor在某个类被注册到IOCContainner的时候,一并添加到该类 ...
- Failed to stop iptables.service: Unit iptables.service not loaded.
redhat 7 [root@lk0 ~]# service iptables stop Redirecting to /bin/systemctl stop iptables.service Fai ...
- 4D卓越团队-两天培训总结
上周末参加了公司组织的领导力培训课程-4D卓越团队(创业型团队领导力训练项目),感觉有一些用,在这里分享一下. 课前游戏 培训老师先带我们做了一个游戏:每一个人,在同时参加培训的人中找到另外的 6 个 ...
- VS2012 Unit Test 个人学习汇总(含目录)
首先,给出MSDN相关地址:http://msdn.microsoft.com/en-us/library/Microsoft.VisualStudio.TestTools.UnitTesting.a ...
- VS2012 Unit Test —— 我对IdleTest库动的大手术以及对Xml相关操作进行测试的方式
[1]我的IdleTest源码地址:http://idletest.codeplex.com/ [2]IdleTest改动说明:2013年10月份在保持原有功能的情况下对其动了较大的手术,首先将基本的 ...
随机推荐
- 股神小D
题目大意: 给定一棵树,每一条边有$L,R$两种权值,求有多少条路径满足$\max(L)\leq\min(R)$. 解法$1-$点分治$+$二维数点 统计树上的路径应首先想到点分治,我们很显然可以搜出 ...
- bzoj 2631: tree link-cut-tree
题目: Description 一棵n个点的树,每个点的初始权值为1.对于这棵树有q个操作,每个操作为以下四种操作之一: + u v c:将u到v的路径上的点的权值都加上自然数c: - u1 v1 u ...
- 【LeetCode】023. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 题 ...
- Cannot resolve class or package 'springframework' less... (Ctrl+F1) Inspection info:Spring XML mode
其实这个问题是由于MySQL 这个jar 包依赖类型默认是runtime ,也就是说只有运行时生效,所以虽然这里报错,但是不影响你代码运行. 解决方案: 将runtime 修改为Compile 即可 ...
- 2018.10.30 一题 洛谷4660/bzoj1168 [BalticOI 2008]手套——思路!问题转化与抽象!+单调栈
题目:https://www.luogu.org/problemnew/show/P4660 https://www.lydsy.com/JudgeOnline/problem.php?id=1168 ...
- HDOJ1073(gets 应用)
练习操作字符串的好题. #include<cstdio> #include<algorithm> #include<cstring> using namespace ...
- Project Online JS 添加Ribbon按钮
var Projects = Projects || {}; (function () { Projects.ribbonButtonClick = function (name) { var pro ...
- asp页面重定向
asp页面重定向 1.当你点击某页面时(没有登录),而此页面需要登录,登录后页面需要定向到你之前操作的页面时 就用到了重定向. 2.login.aspx?redirUrl="重定向的页面地址 ...
- 洛谷-关押罪犯-NOIP2010提高组复赛
题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨气值”(一个正整数值)来表示 ...
- 在64位ubuntu上安装alienbrain客户端
一.首先从Alienbrain_EN_10.5.zip安装包(网上可搜索下载)里提取出linux版安装文件:Installations/Clients/Linux/NoVM/install.bin并c ...