hdu 5298 Solid Geometry Homework(几何)
2015-07-31 22:43
369 查看
题目链接: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;
}
每个圈或者是平面将划分出两个区域,每次把一边区域取反即可。最后判断一下是否满足。
#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;
}
相关文章推荐
- HDU 5045 Contest(状压DP或费用流)
- API注册表函数
- TextView入门
- SQLSERVER 检查字段值域并输出行数和值列表
- 远程登录linux的工具OpenSSH
- Find Minimum in Rotated Sorted Array
- Visual Studio 2008 Package Load Failure:未能正确加载包“Microsoft.VisualStudio.Xaml”
- HDU 4313 Matrix(贪心+并查集)
- mysql_fetch_array容易掉入的陷进
- J哥---------Android 多线程下载 仿下载助手(改进版)
- 局部内部类对外部属性和变量的访问测试
- 黑马程序员——走进面向对象
- Redis数据类型之字典
- 直接用socket实现HTTP下载
- JavaScript--时间显示小插件
- Go语言练习:go语言与C语言的交互——cgo
- Android大图片裁剪终极解决方案(下:拍照截图)
- objectiveC【语法】修饰符 static extern const
- Nginx常用命令介绍
- Oracle 学习之RMAN(十六)Catalog