您的位置:首页 > 其它

codeforce gym 101726 problem C Ekaterinburg Pyramids

2018-04-28 19:30 686 查看
原文链接:http://www.cnblogs.com/BIGTOM/p/8969364.html C. Ekaterinburg Pyramids time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output

Pyramids are frequent structures in ancient civilizations all around the world. The most famous ones, in Egypt, were built over 2000 years before Christ. Other famous pyramids are found in Mexico and Central America, connected to the Mayan and Aztec civilizations.

Little know, however, are the pyramids built in the Ural Mountains, near the city of Ekaterinburg. Such pyramids are from the beginning of the Cristian era, and it is believed that it was built by the Mongols, that invaded Europe through the Ural Mountains from Asia. Differently from the other pyramids, they had a triangular base. Therefore, these pyramids had 4 triangular faces, and since they were held by pillars, no face had to be aligned to the ground.

This was very important, since the pyramid's faces were painted with figures of ancient gods, mythological figures, planets and so on. This way, in some point in the city, a citizen could see one or more faces of the pyramid. This was important in the local religion, and finding a house whose side could see the best faces of the pyramid was greatly valued in that time.

Your task is, given the position of the vertex of the pyramid, and the position of a citizen, determine which faces the citizen can see, considering there's no obstacle between the observer and the pyramid. We consider a point X sees a face if the line segment connecting Xto any point Y in the face does not intersect any other point in the pyramid.

Input

In the first line an integer T, the number of test cases.

Each test case has 5 lines, each with 3 integers. The lines represent the points A, B, C, D and X, respectively, where X is the position of the citizen and the remaining points are the vertex of the pyramid.

Limits

  • 1 ≤ T ≤ 103
  • All points have coordinates with absolute value not exceeding 100.
  • The points A, B, C and D are not coplanar.
  • All points are distinct.
  • The point X is not in the interior nor in any face of the pyramid.
Output

for each instance, print a line with 4 characters. The first must be Y if the citizen can see the face of the pyramid opposed to the vertex A, or N otherwise. The second, third and fourth character must be printed analogously for B, C and D, respectively.

Example input Copy
3
0 0 0
1 0 0
0 1 0
0 0 1
1 1 1
0 0 0
1 0 0
0 1 0
0 0 1
-1 -1 -1
0 0 0
1 0 0
0 1 0
0 0 1
1 1 0
output Copy
YNNN
NYYY
YNNN
思路:任意从四面体内部选取一个点,判断外部点是否与内部点在一个面的一侧即可,在一侧则看不到。判断是否在一侧等价于混合积正负性是否相同。(觉得这题我写的代码很优美!)
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <cstdlib>
5 #include <cstdio>
6 #include <cmath>
7 #include <string>
8 #include <cstring>
9 #include <algorithm>
10 #include <queue>
11 #include <stack>
12 #include <vector>
13 #include <set>
14 #include <map>
15 #include <list>
16 #include <iomanip>
17 #include <cctype>
18 #include <cassert>
19 #include <bitset>
20 #include <ctime>
21
22 using namespace std;
23
24 #define pau system("pause")
25 #define ll long long
26 #define pii pair<int, int>
27 #define pb push_back
28 #define mp make_pair
29 #define clr(a, x) memset(a, x, sizeof(a))
30
31 const double pi = acos(-1.0);
32 const int INF = 0x3f3f3f3f;
33 const int MOD = 1e9 + 7;
34 const double EPS = 1e-9;
35
36 /*
37 #include <ext/pb_ds/assoc_container.hpp>
38 #include <ext/pb_ds/tree_policy.hpp>
39
40 using namespace __gnu_pbds;
41 tree<pli, null_type, greater<pli>, rb_tree_tag, tree_order_statistics_node_update> T;
42 */
43
44 struct point {
45     double x, y, z;
46     point() {}
47     point (double x, double y, double z) : x(x), y(y), z(z) {}
48     void input() {
49         scanf("%lf%lf%lf", &x, &y, &z);
50     }
51     point operator - (const point &p) const {
52         return point(x - p.x, y - p.y, z - p.z);
53     }
54     point operator ^ (const point &p) const {
55         return  point(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
56     }
57     double operator * (const point &p) const {
58         return x * p.x + y * p.y + z * p.z;
59     }
60 } p[7];
61 bool ok(point p1, point p2, point p3, point p4, point p5) {
62     double v1 = (p4 - p1) * ((p2 - p1) ^ (p3 - p1));
63     double v2 = (p5 - p1) * ((p2 - p1) ^ (p3 - p1));
64     return v1 * v2 < -EPS;
65 }
66 int t;
67 int main() {
68     scanf("%d", &t);
69     while (t--) {
70         for (int i = 1; i <= 5; ++i) {
71             p[i].input();
72         }
73         p[6] = point(0, 0, 0);
74         for (int i = 1; i <= 4; ++i) {
75             p[6].x += p[i].x / 4;
76             p[6].y += p[i].y / 4;
77             p[6].z += p[i].z / 4;
78         }
79         putchar(ok(p[2], p[3], p[4], p[5], p[6]) ? 'Y' : 'N');
80         putchar(ok(p[1], p[3], p[4], p[5], p[6]) ? 'Y' : 'N');
81         putchar(ok(p[1], p[2], p[4], p[5], p[6]) ? 'Y' : 'N');
82         putchar(ok(p[1], p[2], p[3], p[5], p[6]) ? 'Y' : 'N');
83         puts("");
84     }
85     return 0;
86 }
View Code

 



转载于:https://www.cnblogs.com/BIGTOM/p/8969364.html

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