Rendezvous on a Tetrahedron (模拟)
Rendezvous on a Tetrahedron
时间限制: 1 Sec 内存限制: 128 MB提交: 6 解决: 4
[提交] [状态] [讨论版] [命题人:admin]
题目描述
One day, you found two worms P and Q crawling on the surface of a regular tetrahedron with four vertices A, B, C, and D. Both worms started from the vertex A, went straight ahead, and stopped crawling after a while.
When a worm reached one of the edges of the tetrahedron, it moved on to the adjacent face and kept going without changing the angle to the crossed edge (figure G.1).
Write a program which tells whether or not P and Q were on the same face of the tetrahedron when they stopped crawling.
You may assume that each of the worms is a point without length, area, or volume.
Incidentally, lengths of the two trails the worms left on the tetrahedron were exact integral multiples of the unit length. Here, the unit length is the edge length of the tetrahedron. Each trail is more than 0.001 unit distant from any vertices, except for its start point and its neighborhood.
This means that worms have crossed at least one edge. Both worms stopped at positions more than 0.001 unit distant from any of the edges.
The initial crawling direction of a worm is specified by two items: the edge XY which is the first edge the worm encountered after its start, and the angle d between the edge AX and the direction of the worm, in degrees.
figure G.2 shows the case of Sample Input 1. In this case, P went over the edge CD and stopped on the face opposite to the vertex A, while Q went over the edge DB and also stopped on the same face.
When a worm reached one of the edges of the tetrahedron, it moved on to the adjacent face and kept going without changing the angle to the crossed edge (figure G.1).
Write a program which tells whether or not P and Q were on the same face of the tetrahedron when they stopped crawling.
You may assume that each of the worms is a point without length, area, or volume.
Incidentally, lengths of the two trails the worms left on the tetrahedron were exact integral multiples of the unit length. Here, the unit length is the edge length of the tetrahedron. Each trail is more than 0.001 unit distant from any vertices, except for its start point and its neighborhood.
This means that worms have crossed at least one edge. Both worms stopped at positions more than 0.001 unit distant from any of the edges.
The initial crawling direction of a worm is specified by two items: the edge XY which is the first edge the worm encountered after its start, and the angle d between the edge AX and the direction of the worm, in degrees.
figure G.2 shows the case of Sample Input 1. In this case, P went over the edge CD and stopped on the face opposite to the vertex A, while Q went over the edge DB and also stopped on the same face.
输入
The input consists of a single test case, formatted as follows.
XP YP dP lP
XQYQ dQ lQ
XWYW (W = P, Q) is the first edge the worm W crossed after its start. XWYW is one of BC,CD or DB.
An integer dW (1 ≤ dW ≤ 59) is the angle in degrees between edge AXW and the initial direction of the worm W on the face △AXWYW .
An integer lW (1 ≤ lW ≤ 20) is the length of the trail of worm W left on the surface, in unit lengths.
XP YP dP lP
XQYQ dQ lQ
XWYW (W = P, Q) is the first edge the worm W crossed after its start. XWYW is one of BC,CD or DB.
An integer dW (1 ≤ dW ≤ 59) is the angle in degrees between edge AXW and the initial direction of the worm W on the face △AXWYW .
An integer lW (1 ≤ lW ≤ 20) is the length of the trail of worm W left on the surface, in unit lengths.
输出
Output YES when and only when the two worms stopped on the same face of the tetrahedron.
Otherwise, output NO.
Otherwise, output NO.
样例输入
CD 30 1
DB 30 1
样例输出
YES
思路:
将正四面体转化到二维平面,根据二维坐标找到所在的面,判断两个面是否相等。
代码如下:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double pi=(acos(-1)); const double sq3=sqrt(3),sq32=sq3/2.0; struct node{ double x,y,angle; }; char s[3]; int d,l; int solve(){ scanf("%s%d%d",s,&d,&l); char ch=s[0]; double angle=1.0*d/180*pi; if(ch=='D') angle=2*pi-angle; else if(ch=='B') angle=5.0*pi/3-angle; else angle=4.0*pi/3-angle; node a=node{cos(angle)*l,sin(angle)*l,angle}; while(a.y<-sq3){ a.y+=sq3; a.x+=1; } a.x+=1,a.y+=sq3; double y=a.y*2/sq3,x=a.x-y*0.5; while(x<0) x+=2; while(x>2) x-=2; if(x<1 && y<1) return (x+y<1)?2:1; if(1<x && x<2 && y<1) return (x-1+y<1)?3:4; if(x<1 && 1<y && y<2) return (x+y-1<1)?4:3; if(1<x && 1<y && y<2) return (x-1+y-1<1)?1:2; return -1; } int main(){ return puts(solve()==solve()?"YES":"NO"),0; }