To calculate intersection volume of n cubes, we need to find maximum value of first corner coordinates (x1,y1,z1) and minimum value of another corner coordinates(x2,y2,z2). There will be intersection between these cubes if and only if the difference between (x2-x1),(y2-y1),(z2-z1) is positive.
Code(c++):
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
IOS
int test,tc=0;
cin>>test;
while(test--)
{
int n,a=0,b=0,c=0,d=INT_MAX,e=INT_MAX,f=INT_MAX;
cin>>n;
for(int i = 0;i<n;i++)
{
int x1,y1,z1,x2,y2,z2;
cin>>x1>>y1>>z1>>x2>>y2>>z2;
a = max(a,x1);
b = max(b,y1);
c = max(c,z1);
d = min(d,x2);
e = min(e,y2);
f = min(f,z2);
}
if(d>a && e>b && f>c)
{
ll res = (d-a)*(e-b)*(f-c);
cout << "Case "<< ++tc<< ": "<<res <<endl;
}
else
cout << "Case "<< ++tc <<": 0\n";
}
return 0;
}
This site solely purposed on personal improvement. Consists my concepts and idea of several problem from well known online judges like LightOj, Leetcode, Codeforces, UVA, SPOJ etc.
Tuesday, 16 April 2019
Intersection of Cubes LightOj 1211
Subscribe to:
Post Comments (Atom)
Monkey Banana Problem lightoj 1004
In this problem we will check which adjacent cell will benefits the monkey best. For this, we will check all possible solution of this pro...
-
Problem link In this problem you will be given two integer number a and b. You need to make a and b equal in exactly k operation(s). In one...
-
In this problem we will check which adjacent cell will benefits the monkey best. For this, we will check all possible solution of this pro...
No comments:
Post a Comment
If you have any doubts, let me know through comments