您的位置:首页 > 其它

HDOJ 5298 Solid Geometry Homework

2015-08-02 16:55 225 查看
空间染色。。。找到数学上的关系就不难了。。。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int maxn = 100005;

struct Plane
{
LL a, b, c, d;
}a[maxn];

struct Circle
{
LL x, y, z, r;
}b[maxn];

struct Point
{
LL x, y, z;
Point(LL x = 0, LL y = 0, LL z = 0) : x(x), y(y), z(z) {}
};

int n, m, p, q;

bool f1(Plane t1, Point t2)
{
return t1.a * t2.x + t1.b * t2.y + t1.c * t2.z + t1.d > 0;
}

bool f2(Circle t1, Point t2)
{
LL t = (t1.x - t2.x) * (t1.x - t2.x) + (t1.y - t2.y) * (t1.y - t2.y) + (t1.z - t2.z) * (t1.z - t2.z);
return t > t1.r * t1.r;
}

bool f(Point t1)
{
bool res = 0;
for(int i = 1; i <= n; i++) res ^= f1(a[i], t1);
for(int i = 1; i <= m; i++) res ^= f2(b[i], t1);
return res;
}

void work()
{
LL x, y, z;
scanf("%d%d%d%d", &n, &m, &p, &q);

for(int i = 1; i <= n; i++) scanf("%lld%lld%lld%lld", &a[i].a, &a[i].b, &a[i].c, &a[i].d);
for(int i = 1; i <= m; i++) scanf("%lld%lld%lld%lld", &b[i].x, &b[i].y, &b[i].z, &b[i].r);

if(p == 0) {
for(int i = 1; i <= q; i++) {
scanf("%lld%lld%lld", &x, &y, &z);
printf("Both\n");
}
return;
}

int res = 0, ok = 1;
scanf("%lld%lld%lld", &x, &y, &z);
res = f(Point(x, y, z));
for(int i = 2; i <= p; i++) {
scanf("%lld%lld%lld", &x, &y, &z);
int t = f(Point(x, y, z));
if(t != res) ok = 0;
}

if(ok == 0) {
for(int i = 1; i <= q; i++) scanf("%lld%lld%lld", &x, &y, &z);
printf("Impossible\n");
return;
}

for(int i = 1; i <= q; i++) {
scanf("%lld%lld%lld", &x, &y, &z);
int t = f(Point(x, y, z));
if(t == res) printf("Y\n");
else printf("R\n");
}
}

int main()
{
int _;
scanf("%d", &_);
for(int i = 1; i <= _; i++) {
work();
if(i != _) printf("\n");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: