HDU 5298 Solid Geometry Homework(异或)

官方题解说的挺详细的。。。

HDU 5298 Solid Geometry Homework(异或)_第1张图片

HDU 5298 Solid Geometry Homework(异或)_第2张图片

HDU 5298 Solid Geometry Homework(异或)_第3张图片

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define LL long long
#define ULL unsigned long long

struct Plane {
    LL a, b, c, d;
    Plane() {}
    Plane(LL _a, LL _b, LL _c, LL _d):
        a(_a), b(_b), c(_c), d(_d) {}
}pn[110];

struct Sphere {
    LL x, y, z, r;
    Sphere() {}
    Sphere(LL _x, LL _y, LL _z, LL _r):
        x(_x), y(_y), z(_z), r(_r) {}
}ss[20];

struct Point {
    LL x, y, z;
    int val;
    Point() {}
    Point(LL _x, LL _y, LL _z, int _v):
        x(_x), y(_y), z(_z), val(_v) {}
}pp[210];

int sgn(LL x) {
    return x > 0 ? 1 : 0;
}

int main() {
//    freopen("hdoj5298.in", "r", stdin);
    int cas;
    scanf("%d", &cas);
    for(int t = 0; t <  cas; t++) {
        if(t)
        puts("");
        int m, n, p, q;
        scanf("%d%d%d%d", &m, &n, &p, &q);
        LL x, y, w, z;
        for(int i = 0; i < m; i++) {
            scanf("%I64d%I64d%I64d%I64d", &x, &y, &w, &z);
            pn[i] = Plane(x, y, w, z);
        }
        for(int i = 0; i < n; i++) {
            scanf("%I64d%I64d%I64d%I64d", &x, &y, &w, &z);
            ss[i] = Sphere(x, y, w, z);
        }
        for(int i = 0; i < p; i++) {
            scanf("%I64d%I64d%I64d", &x, &y, &z);
            pp[i] = Point(x, y, z, 0);
        }

        for(int i = 0; i < p; i++) {
            for(int j = 0; j < m; j++)
                pp[i].val ^= sgn(pp[i].x * pn[j].a + pp[i].y * pn[j].b + pp[i].z * pn[j].c + pn[j].d);
            for(int j = 0; j < n; j++)
                pp[i].val ^= sgn((pp[i].x - ss[j].x) * (pp[i].x - ss[j].x) +
                                 (pp[i].y - ss[j].y) * (pp[i].y - ss[j].y) +
                                 (pp[i].z - ss[j].z) * (pp[i].z - ss[j].z) - ss[j].r * ss[j].r);
        }
        int k;
        if(p) {
            int key = pp[0].val;
            for(k = 1; k < p; k++)
                if(pp[k].val != key)
                    break;
        }
        int val;
        for(int i = 0; i < q; i++) {
            val = 0;
            scanf("%I64d%I64d%I64d", &x, &y, &z);
            if(p && k == p) {
                if(p) {
                    for(int j = 0; j < m; j++)
                        val ^= sgn(x * pn[j].a + y * pn[j].b + z * pn[j].c + pn[j].d);
                    for(int j = 0; j < n; j++)
                        val ^= sgn((x - ss[j].x) * (x - ss[j].x) +
                                   (y - ss[j].y) * (y - ss[j].y) +
                                   (z - ss[j].z) * (z - ss[j].z) - ss[j].r * ss[j].r);
                    if(val == pp[0].val)
                        puts("Y");
                    else
                        puts("R");
                }
            }
            if(!p)
                puts("Both");
        }
        if(p && k != p)
            puts("Impossible");
    }
    return 0;
}


你可能感兴趣的:(ACM,—,其他)