-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1188.cc
70 lines (57 loc) · 1.39 KB
/
1188.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//Name: Gleaming the Cubes
//Level: 2
//Category: 数学
//Note:
/*
* 全ての立方体の共通部分を求めるだけなので,共通部分だけを記憶して逐次処理すればよい.
* それぞれの座標軸は独立なので,各座標軸ごとに共通範囲を求める.
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <climits>
using namespace std;
struct Box {
int pos[3];
int len[3];
Box() {}
Box operator &=(const Box &other) {
for(int i = 0; i < 3; ++i) {
int np = max(pos[i], other.pos[i]);
int nl = min(pos[i]+len[i], other.pos[i]+other.len[i]) - np;
if(nl < 0) nl = 0;
pos[i] = np;
len[i] = nl;
}
return *this;
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
while(true) {
int N;
cin >> N;
if(!N) break;
Box b;
for(int i = 0; i < 3; ++i) {
b.pos[i] = 0;
b.len[i] = INT_MAX;
}
while(N--) {
Box nb;
int len;
for(int i = 0; i < 3; ++i) {
cin >> nb.pos[i];
}
cin >> len;
for(int i = 0; i < 3; ++i) {
nb.len[i] = len;
}
b &= nb;
}
cout << b.len[0]*b.len[1]*b.len[2] << endl;
}
return 0;
}