hdu 5298 Solid Geometry Homework(几何)

582 篇文章 0 订阅
99 篇文章 0 订阅

题目链接:hdu 5298 Solid Geometry Homework


每个圈或者是平面将划分出两个区域,每次把一边区域取反即可。最后判断一下是否满足。


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;
const int maxn = 3000;
typedef long long ll;

struct Point {
	int type;
	ll x, y, z;
	Point (int type = 0, ll x = 0, ll y = 0, ll z = 0) {
		this->type = type;
		this->x = x;
		this->y = y;
		this->z = z;
	}
};

struct Shape {
	int type;
	ll a, b, c, d;
	Shape (int type = 0, ll a = 0, ll b = 0, ll c = 0, ll d = 0) {
		this->type = type;
		this->a = a;
		this->b = b;
		this->c = c;
		this->d = d;
	}
	bool judge (Point u) {
		if (type) {
			ll ta = u.x - a, tb = u.y - b, tc = u.z - c;
			return ta * ta + tb * tb + tc * tc - d * d > 0;
		}
		return a * u.x + b * u.y + c * u.z + d > 0;
	}
};

int M, N, P, Q, V[maxn];
vector<Shape> s;
vector<Point> p;

void init () {
	s.clear();
	p.clear();
	memset(V, 0, sizeof(V));

	ll a, b, c, d;
	scanf("%d%d%d%d", &M, &N, &P, &Q);
	for (int i = 0; i < M; i++) {
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		s.push_back(Shape(0, a, b, c, d));
	}
	for (int i = 0; i < N; i++) {
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		s.push_back(Shape(1, a, b, c, d));
	}
	for (int i = 0; i < P; i++) {
		scanf("%lld%lld%lld", &a, &b, &c);
		p.push_back(Point(0, a, b, c));
	}
	for (int i = 0; i < Q; i++) {
		scanf("%lld%lld%lld", &a, &b, &c);
		p.push_back(Point(1, a, b, c));
	}
}

void solve () {
	if (P == 0) {
		for (int i = 0; i < Q; i++)
			printf("Both\n");
		return;
	}

	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < p.size(); j++) {
			if (s[i].judge(p[j]))
				V[j] ^= 1;
		}
	}

	int yellow = -1;
	for (int i = 0; i < p.size(); i++) {
		if (p[i].type == 0) {
			if (yellow == -1)
				yellow = V[i];
			else if (yellow != V[i]) {
				printf("Impossible\n");
				return;
			}
		}
	}

	for (int i = 0; i < p.size(); i++) {
		if (p[i].type) {
			printf("%s\n", V[i] == yellow ? "Y" : "R");
		}
	}
}

int main () {
	int cas;
	scanf("%d", &cas);
	while (cas--) {
		init();
		solve();
		if (cas)
			printf("\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值