codeforce gym 101726 problem C Ekaterinburg Pyramids
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.
InputIn 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.
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 Copy3output Copy
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
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
- codeforce gym 101726 problem B. Spy Duel
- codeforce gym 101726 problem A. Popularity on Facebook
- codeforce Gym 100500F Door Lock (二分)
- codeforce Gym 100500A Poetry Challenge(博弈,暴搜)
- codeforce Gym 100418K Cards (概率,数学)
- Problem 56E Codeforce E—Domino Principle
- Codeforce Gym 100819L : 2015-2016 ACM-ICPC Pacific Northwest Regional Contest - L 这是一道阅读理解(微笑)
- codeforce Gym 100500I Hall of Fame (水)
- codeforce Gym 100500H ICPC Quest (简单dp)
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- codeforce Gym 100342J Triatrip (bitset)
- codeforce Gym 100203I I WIN (网络流)
- 【codeforce Gym 100570B】【最短路SPFA】 ShortestPath Query 【询问单源最短路径,每条边有一个颜色,要求路径上相邻边的颜色不能相同】
- codeforce Gym 100342H Hard Test (思考题)
- Codeforce GYM 100741 A. Queries
- codeforce Gym 100570B ShortestPath Query (最短路SPFA)
- codeforce contest 103 problem D Time to Raid Cowavans(根号算法)
- Codeforces GYM 100960B: ForceField 题解
- codeforce Gym 100425E The Street Escalator(期望,线性递推)
- codeforce gym 100548H The Problem to Make You Happy