1188 Gleaming the Cubes

原创 2007年10月15日 08:35:00
Gleaming the Cubes
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 428   Accepted: 213

Description
As chief engineer of the Starship Interprize, the task of repairing the hyperstellar, cubic, transwarped-out software has fallen on your shoulders. Simply put, you must compute the volume of the intersection of anywhere from 2 to 1000 cubes.

Input
The input consists of several sets of cubes for which the volume of their intersections must be computed. The first line of each set contains a number (from 2 to 1000) which indicates the number of cubes which follow, one cube per line. Each line which describes a cube contains four integers. The first three integers are the x, y, and z coordinates of the corner of a cube, and the fourth integer is the positive distance which the cube extends in each of the three directions (parallel to the x, y, and z axes) from that corner.

Following the data for the first set of cubes will be a number which indicates how many cubes are in a second set, followed by the cube descriptions for the second set, again one per line. Following this will be a third set, and so on.A number =0 indicate the end of input.

Output
Your program should process sets all of cubes, outputting the volume of their intersections to the output file, one set per line, until a zero is read for the number of cubes.

Sample Input

 

Sample Output

 

Source
Mid-Central USA 1993

 ******************************************************************************************

********************************************************************************************

Source Code
#include <iostream>
using namespace std;
struct Pot {
	int x,y,z;
}L,R,C;
int main() {
	int N,x,y,z,len;
	while(cin >> N,N!=0) {
		L.x = L.y = L.z = len = 0;
		cin >> L.x >> L.y >> L.z >> len;
		R.x = L.x + len;
		R.y = L.y + len;
		R.z = L.z + len;
		N--;
		bool flag = 1;
		while(N--) {
			C.x = C.y = C.z = len = 0;
			cin >> C.x >> C.y >> C.z >> len;
			if(C.x>=R.x||C.y>=R.y||C.z>=R.z)	{	flag = 0;break;}
			if(C.x+len<=L.x||C.y+len<=L.y||C.z+len<=L.z)	{flag =  0;break;}
			if(C.x>L.x)	L.x = C.x;
			if(C.y>L.y)	L.y = C.y;
			if(C.z>L.z)	L.z = C.z;
			if(C.x+len<R.x)	R.x = C.x+len;	
			if(C.y+len<R.y)	R.y = C.y+len;
			if(C.z+len<R.z)	R.z = C.z+len;
		}
		while(N>0)	{N--;cin >> C.x >> C.y >> C.z >> len;}
		if(flag == 0)	{cout << 0 << endl; continue;}
		cout << (R.x-L.x)*(R.y-L.y)*(R.z-L.z) << endl;
	}
	return 0;
}

25
9
2
0 0 0 10
9 1 1 5
3
0 0 0 10
9 1 1 5
8 2 2 3
0

POJ 1188 Gleaming the Cubes

题意:给定n个正方体,求他们的交体积。 题解:知道两个长方体相交的算法就能很简单的解出这道题,实际上两个长方体交,就是取x1,y1,z1各自的最大值,以及x2,y2,z2各自的最小值就是了。 #i...
  • tmeteorj
  • tmeteorj
  • 2013-03-12 17:39:17
  • 1054

POJ 1188 Gleaming the Cubes 笔记

求多个立方体交集的体积。每个立方体给出 x,y,z,和正方向延伸出的距离。...
  • woniupengpeng
  • woniupengpeng
  • 2017-05-15 12:07:00
  • 459

UVa 737 - Gleaming the Cubes

題目:求n個立方體的公共部分的體積。 分析:計算幾何。直接求出每個維度的最大的最小值和最小的最大值,做差求積即可。 說明:注意如果摸個維度是負數,則取0。 #include #include ...
  • mobius_strip
  • mobius_strip
  • 2016-01-11 09:23:50
  • 510

Playing Cubes

Playing Cubes Petya and Vasya decided to play a little. They found n red cubes and m blue cubes....
  • u013008291
  • u013008291
  • 2015-02-13 14:32:23
  • 369

51 NOD 1188 最大公约数之和 V2(基础数论)

数学 推导公式 欧拉筛法
  • qingshui23
  • qingshui23
  • 2016-08-10 17:24:37
  • 972

51nod 1188 最大公约数之和 V2

https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1188 给出一个数N,输出小于等于N的所有数,两两之间...
  • u013238393
  • u013238393
  • 2016-10-28 20:39:52
  • 154

zoj 1188 - DNA Sorting

题目:给你一些DNA串,按nixush 分析: 说明:
  • mobius_strip
  • mobius_strip
  • 2014-09-16 12:46:31
  • 369

一个极简的Marching Cubes算法实现

从网上down了一个MC算法代码,发现里面还是有很多冗余代码,经过删除,修改,实现了一个极简单的MC算法实现,可以绘制三角面片模拟等值面,供初学者参考,完整代码贴出: #include #inc...
  • qq_38812796
  • qq_38812796
  • 2017-08-08 18:46:39
  • 381

Marching Cubes Module

  • 2011年07月20日 09:30
  • 114KB
  • 下载

51Nod-1188-最大公约数之和 V2

ACM模版描述题解题目要求所有小于等于 NN 的两两之间的最大公约数的和,如果我们直接这么考虑两者之间的关系其实并不好想,我们可以先固定一个来考虑。如果我们求 [1,n][1, n] 与 mm 的 G...
  • f_zyj
  • f_zyj
  • 2017-08-08 21:48:56
  • 245
收藏助手
不良信息举报
您举报文章:1188 Gleaming the Cubes
举报原因:
原因补充:

(最多只允许输入30个字)