1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include<iostream> #include<cmath> #define P(x,y) Pi[x].position[y] using namespace std; int N; bool A[4]; struct piece { char name; int position[2]; }Pi[10];
inline bool f1(int i, int j, bool po) { if (P(i, (po + 1) % 2) != P(j, (po + 1) % 2)) return 0; int ii = P(i, po) - P(0, po), jj = P(j, po) - P(0, po); if (ii > 0 && jj > 0 && ii > jj) return 1; if (ii < 0 && jj < 0 && ii < jj) return 1; return 0; } inline bool f2(int i) { if (P(i, 0) == P(0, 0) && abs(P(i, 1) - P(0, 1)) == 1) return 1; if (P(i, 1) == P(0, 1) && abs(P(i, 0) - P(0, 0)) == 1) return 1; return 0; } bool f3(int i, int xx, int yy) { if ((abs(xx) == 2 && abs(yy) == 1) || (abs(xx) == 1 && abs(yy) == 2)) { for (int j = 0;j <= N;++j) { if (P(j, 0) == P(i, 0) - int(xx / 2) && P(j, 1) == P(i, 1) - int(yy / 2)) return 0; } return 1; } return 0; } void GR(int i, bool po) { if (P(i, (po + 1) % 2)>P(0, (po + 1) % 2) + 1 || P(i, (po + 1) % 2) < P(0, (po + 1) % 2) - 1) return; int j = 1; for (;j <= N&&!f1(i, j, po);++j); if (j > N) { if (P(i, (po + 1) % 2) == P(0, (po + 1) % 2) - 1) { if (!f2(i)) A[(po + 1) % 2] = 1; } else if (P(i, (po + 1) % 2) == P(0, (po + 1) % 2) + 1) { if (!f2(i))A[(po + 1) % 2 + 2] = 1; } else if (f2(i)) P(i, po) - P(0, po) > 0 ? A[po] = 1 : A[po + 2] = 1; else A[po] = A[po + 2] = 1; } } void H(int i) { if (f2(i)) return; if (!A[0] && f3(i, P(i, 0) - (P(0, 0) - 1), P(i, 1) - P(0, 1))) A[0] = 1; if (!A[1] && f3(i, P(i, 0) - P(0, 0), P(i, 1) - (P(0, 1) - 1))) A[1] = 1; if (!A[2] && f3(i, P(i, 0) - (P(0, 0) + 1), P(i, 1) - P(0, 1))) A[2] = 1; if (!A[3] && f3(i, P(i, 0) - P(0, 0), P(i, 1) - (P(0, 1) + 1))) A[3] = 1; } void C(int i, bool po) { if (f2(i) || P(i, (po + 1) % 2) > P(0, (po + 1) % 2) + 1 || P(i, (po + 1) % 2) < P(0, (po + 1) % 2) - 1) return; int flag = 0; for (int j = 1;j <= N;++j) if (f1(i, j, po)) ++flag; if (flag == 1) { if (P(i, (po + 1) % 2) == P(0, (po + 1) % 2) - 1) A[(po + 1) % 2] = 1; else if (P(i, (po + 1) % 2) == P(0, (po + 1) % 2) + 1) A[(po + 1) % 2 + 2] = 1; else { int j = 1; for (;j <= N;++j) if (f1(i, j, po) && f2(j)) break; if (j <= N) P(i, po) - P(0, po) > 0 ? A[po] = 1 : A[po + 2] = 1; else A[po] = A[po + 2] = 1; } } }
int main() { while ((cin >> N >> P(0, 0) >> P(0, 1)) && N && P(0, 0) && P(0, 1)) { for (int i = 1;i <= N;++i) cin >> Pi[i].name >> P(i, 0) >> P(i, 1); A[0] = (P(0, 0) == 1 ? 1 : 0); A[1] = (P(0, 1) == 4 ? 1 : 0); A[2] = (P(0, 0) == 3 ? 1 : 0); A[3] = (P(0, 1) == 6 ? 1 : 0); for (int i = 1;i <= N;++i) { if (Pi[i].name == 'G') GR(i, 0); else if (Pi[i].name == 'R') GR(i, 0), GR(i, 1); else if (Pi[i].name == 'H') H(i); else C(i, 0), C(i, 1); } int i; for (i = 0;i < 4 && A[i];++i); cout << (i < 4 ? "NO" : "YES") << '\n'; } return 0; }
|