light oj 1211 - Intersection of Cubes (计算几何)

本文介绍了一种计算多个立方体重叠部分体积的方法。通过输入每个立方体的两个对角点坐标,程序能够处理多达100个立方体,并计算它们相交区域的总体积。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      1211 - Intersection of Cubes
Time Limit: 0.5 second(s)Memory Limit: 32 MB

You are given n cubes, each cube is described by twopoints in 3D space:(x1, y1, z1) beingone corner of the cube and(x2, y2, z2)being the opposite corner. Assume that the sides of each of the cubes areparallel to the axis. Your task is to find the volume of their intersection.

Input

Input starts with an integer T (≤ 100),denoting the number of test cases.

Each case starts with a line containing an integer n (1≤ n ≤ 100). Each of the nextn lines contains sixintegersx1 y1 z1 x2 y2z2 (1 ≤ x1, y1, z1, x2,y2, z2 ≤ 1000, x1 < x2, y1< y2, z1 < z2) where (x1,y1, z1) is the co-ordinate of one corner and(x2,y2, z2) is the co-ordinate of the opposite corner.

Output

For each case, print the case number and volume of theirintersection.

Sample Input

Output for Sample Input

2

2

1 1 1 3 3 3

1 1 1 2 2 2

3

7 8 9 20 20 30

2 2 2 50 50 50

13 14 15 18 30 40

Case 1: 1

Case 2: 450

 

这题是要求所有立方体重叠部分的体积,首先从两个立方体的情况考虑然后推广到N个,不然情况太乱,从最简单的模型入手容易把问题想清楚

先从一个顶点入手然后分配坐标,下发到每一个立方体


Problem Setter: Jane Alam Jan    

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
const int inf = 0x3f3f3f3f;


int main()
{
    int t, ncase=1;
    scanf("%d", &t);
    while(t--)
    {
        int n;
        scanf("%d", &n);
        int a[]={0,0,0,0,inf,inf,inf};
        while(n--)
        {
            for(int i=1; i<=3; i++)
            {
                int tmp;
                scanf("%d", &tmp);
                if(tmp>a[i])
                {
                    a[i]=tmp;
                }
            }
            for(int i=4; i<=6; i++)
            {
                int tmp;
                scanf("%d", &tmp);
                if(tmp<a[i])
                {
                    a[i]=tmp;
                }
            }
        }
        if(a[1]<=a[4]&&a[2]<=a[5]&&a[3]<=a[6])
        {
            int v=(a[4]-a[1])*(a[5]-a[2])*(a[6]-a[3]);
            printf("Case %d: %d\n",ncase++,v);
        }
        else
        {
            printf("Case %d: 0\n",ncase++);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值