📄 3568923_ac_0ms_468k.cc
字号:
#include <string>
#include <sstream>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
class Cubic
{
private :
int x, y, z, xl, yl, zl;
public:
Cubic(string str)
{
istringstream sin (str);
sin >> x >> y >> z >> xl;
yl = zl = xl;
}
Cubic(int _x, int _xl, int _y, int _yl, int _z, int _zl)
{
x = _x;xl = _xl;
y = _y;yl = _yl;
z = _z;zl = _zl;
}
int getVolume()
{
return xl * yl * zl;
}
Cubic()
{
}
PII getX()
{
return make_pair(x, x + xl);
}
PII getY()
{
return make_pair(y, y + yl);
}
PII getZ()
{
return make_pair(z, z + zl);
}
PII getCommon(PII a, PII b)
{
int a1, a2;
int b1, b2;
a1 = a.first;a2= a.second;
b1 = b.first;b2 = b.second;
if (b2 <= a1 || b1 >= a2)
{
return make_pair(0, 0);
}
return make_pair(max(a1, b1), min(a2, b2));
}
Cubic intersect(Cubic cubic)
{
PII X = getCommon(this->getX(), cubic.getX());
if (X.first >= X.second)
{
return Cubic("0 0 0 0");
}
PII Y = getCommon(this->getY(), cubic.getY());
if (Y.first >= Y.second)
{
return Cubic("0 0 0 0");
}
PII Z = getCommon(this->getZ(), cubic.getZ());
if (Z.first >= Z.second)
{
return Cubic("0 0 0 0");
}
return Cubic(
X.first, X.second - X.first,
Y.first, Y.second - Y.first,
Z.first, Z.second - Z.first
);
}
};
int main()
{
int n;
string line;
Cubic cubic;
while (true)
{
cin >> n;
getchar();
if (n == 0)
{
break;
}
getline(cin, line);
cubic = Cubic(line);
for (int i = 1; i < n; i++)
{
getline(cin, line);
cubic = cubic.intersect(Cubic(line));
}
printf("%d\n", cubic.getVolume());
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -