#include #include #include #include #include #include #include #include #include #include using namespace std; #define FI first #define SE second #define X first #define Y second #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector VI; typedef pair PII; typedef long long LL; typedef long double LD; typedef double D; #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) #define FORE(a,b) for(VAR(a,(b).begin());a!=(b).end();a++) #define VAR(a,b) __typeof(b) a=(b) #define SIZE(a) ((int)(a).size()) #define ALL(x) (x).begin(),(x).end() #define CLR(x,a) memset(x,a,sizeof(x)) class point { public: int x,y; point() {} point(int _x, int _y): x(_x), y(_y) {} bool operator==(const point &A) const { return x==A.x && y==A.y; } bool operator<(const point &A) const { return MP(x,y) < MP(A.x,A.y); } } ; class segment { public: point A, B; segment() {} segment(point _A, point _B): A(_A), B(_B) {} void normalize() { if (A < B) swap(A,B); } bool operator==(const segment &u) const { return A==u.A && B == u.B; } void print() { // printf("%d %d %d %d\n",A.x,A.y,B.x,B.y); } bool operator<(const segment &u) const { return MP(A,B) < MP(u.A,u.B); } } ; inline int iabs(int a) { return a>0?a:-a; } int dist(const point &A, const point &B) { return iabs(A.x - B.x) + iabs(A.y - B.y); } bool between(const point &A, const point &B, const point &C) { return dist(A,B) + dist(B,C) == dist(A,C) && (LL)(B.x-A.x)*(C.y-A.y) == (LL)(C.x-A.x)*(B.y-A.y); } bool overlap(const segment &u, const segment &w) { if ((LL)(u.A.x - u.B.x) * (w.A.y - u.B.y) != (LL)(w.A.x - u.B.x) * (u.A.y - u.B.y)) return false; if ((LL)(u.A.x - u.B.x) * (w.B.y - u.B.y) != (LL)(w.B.x - u.B.x) * (u.A.y - u.B.y)) return false; if (between(u.A,w.A,u.B) && between(u.A,w.B,u.B)) return true; if (between(w.A,u.A,w.B) && between(w.A,u.B,w.B)) return true; bool ok1 = between(w.A,u.A,w.B) || between(w.A,u.B,w.B); bool ok2 = between(u.A,w.A,u.B) || between(u.A,w.B,u.B); return ok1 && ok2; } segment sum(const segment &u, const segment &w) { point t[] = {u.A, u.B, w.A, w.B}; int mx = 0; REP(i,4) FOR(j,i+1,3) mx = max(mx, dist(t[i], t[j])); REP(i,4) FOR(j,i+1,3) if (dist(t[i], t[j]) == mx) { return segment(t[i], t[j]); } return u; } double mx1, mx2; double alfa, aa, bb; const double eps = 1e-7; double dabs(double x) { return x>0?x:-x; } pair obroc(const point &A) { double xx = A.x * aa - A.y * bb; double yy = A.x * bb + A.y * aa; // printf("xx=%lf yy=%lf\n",xx,yy); int XX = floor(xx+eps); int YY = floor(yy+eps); // printf("obroc XX=%d YY=%d\n",XX,YY); if (dabs(xx-XX) < 2 * eps && dabs(yy-YY) < 2 * eps) return MP(point(XX,YY),true); else return MP(point(0,0),false); } double sqr(double x) { return x * x; } double eucl(const point &A, const point &B) { return sqrt(sqr(A.x-B.x) + sqr(A.y-B.y)); } class hutong { public: vector v; void simplify() { random_shuffle(ALL(v)); bool ch=1; while (ch) { ch = 0; int i = 0, j; while (i < SIZE(v)) { j = i + 1; while (j < SIZE(v)) { if (overlap(v[i], v[j])) { v[i] = sum(v[i], v[j]); v[j] = v.back(); v.pop_back(); ch = 1; } else { j++; } } i++; } } } double diameter() { double mx = 0; vector uu; REP(i,SIZE(v)) uu.PB(v[i].A), uu.PB(v[i].B); REP(i,SIZE(uu)) FOR(j,i+1,SIZE(uu)-1) mx = max(mx, eucl(uu[i], uu[j])); return mx; } void normalize() { FORE(e,v) e->normalize(); sort(ALL(v)); } bool operator==(const hutong &H) const { if (SIZE(v) != SIZE(H.v)) return false; REP(i,SIZE(v)) if (!(H.v[i] == v[i])) return false; return true; } } P1, P2; int main() { char buf[100]; int px = 0, py = 0, x = 0, y = 0, dx, dy; while (1) { P1.v.clear(); P2.v.clear(); scanf("%s",buf); if (buf[0] == 'Q') break; x=y=0; while (buf[0] != 'E') { scanf("%d%d",&dx,&dy); px = x, py = y; x += dx, y += dy; if (buf[0] == 'L') { P1.v.PB(segment(point(px,py),point(x,y))); } scanf("%s", buf); } x=y=0; scanf("%s", buf); while (buf[0] != 'E') { scanf("%d%d",&dx,&dy); px = x, py = y; x += dx, y += dy; if (buf[0] == 'L') { P2.v.PB(segment(point(px,py),point(x,y))); } scanf("%s", buf); } P1.simplify(); P2.simplify(); mx1 = P1.diameter(), mx2 = P2.diameter(); bool result = false; P1.normalize(); P2.normalize(); int xx = P1.v[0].A.x, yy=P1.v[0].A.y; REP(i,SIZE(P1.v)) { P1.v[i].A.x -= xx; P1.v[i].A.y -= yy; P1.v[i].B.x -= xx; P1.v[i].B.y -= yy; } // FORE(e,P1.v) e->print(); puts("-------"); // FORE(e,P2.v) e->print(); puts("i*********-------"); // printf("SIZE %d %d\n",SIZE(P1.v),SIZE(P2.v)); if (SIZE(P1.v) == SIZE(P2.v)) { if (SIZE(P1.v) == 0) result = true; REP(i,SIZE(P2.v)) { if ( dabs(eucl(P1.v[0].A, P1.v[0].B) * mx2 - eucl(P2.v[i].A, P2.v[i].B) * mx1) < 0.1) { REP(num,2) { point A = P2.v[i].A, B = P2.v[i].B; if (num) swap(A,B); hutong Q; alfa = atan2(P1.v[0].B.y, P1.v[0].B.x) - atan2(B.y - A.y, B.x - A.x); aa = cos(alfa) * mx1 / mx2; bb = sin(alfa) * mx1 / mx2; // printf("alfa=%lf aa=%lf bb=%lf\n",alfa,aa,bb); bool ok = true; REP(j,SIZE(P2.v)) { point U = point(P2.v[j].A.x - A.x, P2.v[j].A.y - A.y); point W = point(P2.v[j].B.x - A.x, P2.v[j].B.y - A.y); // printf("U.x=%d U.y=%d\n",U.x,U.y); // printf("W.x=%d W.y=%d\n",W.x,W.y); pair uu = obroc(U); pair ww = obroc(W); // printf("%d %d %d\n",uu.X.x,uu.X.y,uu.Y); // printf("%d %d %d\n",ww.X.x,ww.X.y,ww.Y); if (uu.SE && ww.SE) { Q.v.PB(segment(uu.FI,ww.FI)); } else { ok = false; break; } } // FORE(e,Q.v) e->print(); puts("-------"); // printf("ok = %d\n", ok); Q.normalize(); if (Q == P1) { result = true; break; } } } } } puts(result?"YES":"NO"); } return 0; }