#include #include #include #include #include using namespace std; #define debug if(0) const int N = 20004; const long double eps = 1e-8L; const int inf = 1000000; template struct xy { K x, y; xy(K _x=inf, K _y=inf):x(_x),y(_y){}; void print(){ printf("(%d %d)",x,y); } bool operator < (const xy& xy2) const{ if(x!=xy2.x) return x long double operator * (xy a, xy b){ return a.x*b.x + a.y*b.y; } template xy operator - (const xy &a, const xy &b){ return xy(a.x-b.x, a.y-b.y); }; template struct seg { xy a,b; seg(xy _a, xy _b):a(_a), b(_b) {} seg(){} void normalize(){ if(a.x==b.x){ if(a.y> b.y) swap(a,b); } else { if(a.x > b.x) swap(a,b); } } void print(){ printf("<"); a.print(); printf(", "); b.print(); printf(">\n"); } long double len (){ long double X = a.x - b.x; long double Y = a.y - b.y; return sqrt(X*X+Y*Y); } bool operator == (const seg& s2) const { return a.x==s2.a.x && a.y==s2.a.y && b.x==s2.b.x && b.y==s2.b.y; } bool operator < (const seg& s2) const { if(a!=s2.a) return a K det(const xy &a, const xy &b){ return a.x*b.y - b.x*a.y; } template bool parallel(const seg &r, const seg &t){ return det(r.b - r.a, t.a-r.a)==0 && det(r.b - r.a, t.b-r.a)==0; } vector >tmp; bool color[N]; bool should_merge(seg r, seg t){ if(!parallel(r,t)) return false; int a,b,c,d; if(r.a.x==r.b.x){ //pionowy a = r.a.y; b = r.b.y; c = t.a.y; d = t.b.y; } else { a = r.a.x; b = r.b.x; c = t.a.x; d = t.b.x; } if(a>b) swap(a,b); if(c>d) swap(c,d); return (c>=a && c<=b) || (d>=a && d<=b) || (a>=c && a<=d) || (b>=c && b<=d); } seg merge(seg r, seg t){ r.normalize(); t.normalize(); if(r.a.x==r.b.x){ //pionowy seg res; if(r.a.y < t.a.y) res.a = r.a; else res.a = t.a; if(r.b.y > t.b.y) res.b = r.b; else res.b = t.b; return res; } else { seg res; if(r.a.x < t.a.x) res.a = r.a; else res.a = t.a; if(r.b.x > t.b.x) res.b = r.b; else res.b = t.b; return res; } } void normalize(vector >&v){ int n = v.size(); for(int i=0; i >&v){ v.clear(); int x=0, y=0; while(1){ int a,b; scanf("%s", op); if(op[0]=='E') break; if(op[0]=='Q') return false; if(op[0]=='L'){ scanf("%d %d",&a,&b); if(a!=0 || b!=0){ v.push_back(seg(xy(x,y), xy(x+a, y+b))); x+=a; y+=b; } } else { //M scanf("%d %d",&a,&b); x += a; y += b; } } debug {printf("read: %d\n",(int)v.size());} normalize(v); debug {printf("norm: %d\n",(int)v.size());} return true; } long double veclen(xyp, xyq){ return (q.x*p.y-q.y*p.x); } long double kat(seg a, seg b){ xy p (a.b.x-a.a.x, a.b.y-a.a.y); xy q (b.b.x-a.a.x, b.b.y-a.a.y); return atan2(veclen(p,q), p*q); //XXX } xy rotate(xy pt, long double alpha) { return xy(pt.x*cos(alpha) + pt.y*sin(alpha), -pt.x*sin(alpha) + pt.y*cos(alpha)); } int roundd(long double x){ x = round(x)+1000000.5; return ((int)x) - 1000000; } bool ok; seg trans(long double resiz, xy mov, long double alpha, seg s){ debug { printf("\n"); s.print(); } seg res = seg(xy(s.a.x, s.a.y), xy(s.b.x, s.b.y)); res.a.x *= resiz; res.a.y *= resiz; res.b.x *= resiz; res.b.y *= resiz; res.a.x += mov.x; res.a.y += mov.y; res.b.x += mov.x; res.b.y += mov.y; res.a = rotate(res.a, alpha); res.b = rotate(res.b, alpha); xyA(roundd(res.a.x), roundd(res.a.y)); xyB(roundd(res.b.x), roundd(res.b.y)); if(fabs(A.x - res.a.x)>eps) ok = false; if(fabs(A.y - res.a.y)>eps) ok = false; if(fabs(B.x - res.b.x)>eps) ok = false; if(fabs(B.y - res.b.y)>eps) ok = false; segRES(A,B); debug{ printf("translates to\n"); RES.print(); printf("\n"); } return RES; } vector >A,B,C; void sortw(vector >&v){ for(int i=0; i<(int)v.size(); i++) v[i].normalize(); sort(v.begin(), v.end()); } bool TRY(seg a, seg b){ //printf("move %d %d, %d %d\n",a.a.x, a.a.y, b.a.x, b.a.y); for(int i=0; i mov(b.a.x - a.a.x, b.a.y - a.a.y); long double k = kat(a,b); for(int i = 0;i<(int)A.size();i++) { C.push_back(trans(resiz,mov,k,A[i])); } if(!ok) return false; //sortw(B); sortw(C); for(int i=0; i<(int)B.size(); i++){ debug { B[i].print(); C[i].print(); printf("??\n\n"); } if(!(B[i]==C[i])) ok = false; } return ok; } bool solve(){ if(!read(A)) return false; read(B); debug { printf("A:\n"); for(int i=0; i<(int)A.size(); i++) A[i].print(); printf("B:\n"); for(int i=0; i<(int)B.size(); i++) B[i].print(); } if(A.size()!=B.size()){ printf("NO\n"); return true; } for(int i=0; i<(int)A.size(); i++){ for(int j=0; j<(int)B.size(); j++){ debug { printf("TRY %d -> %d\n",i,j); A[i].print(); printf("goes to\n"); B[j].print(); } if(TRY(A[i], B[j])){ printf("YES\n"); return true; } if(TRY(A[i], seg(B[j].b, B[j].a))){ printf("YES\n"); return true; } } } printf("NO\n"); return true; } int main(){ while(1){ if(!solve()) break; } return 0; }