hdu 5298 Solid Geometry Homework
来源:互联网 发布:淘宝详情页思路 编辑:程序博客网 时间:2024/06/13 09:00
http://acm.hdu.edu.cn/showproblem.php?pid=5298
用red和yellow给空间染色,使得相邻区域颜色不同,且指定点所在区域颜色为yellow,问是否存在解和指定点颜色?
立体几何,其实是道水题,将点带入方程判断是在面的哪一侧,保证球面内外,平面上下都是反的,然后再判断一下合法性就ok了!
其实给我的感觉也就是这种成功染色的方法蛮奇妙的!哈哈,还好啦,你就两个点两个点想,这种方法,刚开始颜色是一样的,然后中间经过各种取反,肯定能保证最后相邻两个点的颜色是不相等的!因此就肯定是合法的染色!
#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;}
1 0
- hdu 5298 Solid Geometry Homework
- hdu 5298 Solid Geometry Homework(几何)
- HDOJ 5298 Solid Geometry Homework
- 【HDU】5298 Solid Geometry Homework【暴力+二分图】
- HDU 5298 Solid Geometry Homework(异或)
- 2015多校第一场1001 hdu 5298 Solid Geometry Homework
- Constructive Solid Geometry with the Stencil Buffer
- HDU 4216-Computational Geometry?
- HDU 5605 geometry
- HDU 5605 geometry
- HDU 5605 geometry
- HDU 5605 geometry
- Geometry Problem HDU
- Hdu 5731 Solid Dominoes Tilings
- HDU 1074 Doing Homework
- hdu 1074 Doing Homework
- HDU-1074-Doing Homework
- hdu-doing homework
- C#字典
- [20160213]练习集合
- Key-Value Observing
- opencv学习笔记(一):基于YCrCb颜色空间的肤色检测
- Java 回顾笔记 1
- hdu 5298 Solid Geometry Homework
- uva1330 - City Game
- hdu 1520 树形dp
- 推导条件随机场参数估计的全过程
- uva1121 - Subsequence
- POJ 3692 Kindergarten(最大独立集)
- UI基础-01第一个iOS应用程序
- 区间问题三部曲(1) : 在线区间最值算法
- 20160212