#include #include #include #include #include using namespace std; static const int MAX_SIZE = 1000; struct TILE { int state; pair opposite; }; map, TILE> positionToTile; enum STATE { EMPTY, HEAD, FOOT, SUSPENSION }; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; bool check(int startX, int startY) { positionToTile[make_pair(startX, startY)].state = HEAD; vector > s; s.push_back(make_pair(startX, startY)); while (!s.empty()) { const pair currentPosition = s.back(); s.pop_back(); const TILE& tile = positionToTile[currentPosition]; for (int direction = 0; direction < 4; ++direction) { pair nextPosition = currentPosition; nextPosition.first += dx[direction]; nextPosition.second += dy[direction]; if (positionToTile.find(nextPosition) == positionToTile.end()) { //布団の無い場所 continue; } int nextState = tile.state; if (tile.opposite == nextPosition) { //布団の反対側 nextState = 3 - nextState; } TILE& nextTile = positionToTile.find(nextPosition)->second; if (nextTile.state == nextState) { //既に調べた場所 continue; } else if (nextTile.state == SUSPENSION) { //まだ調べていない場所 nextTile.state = nextState; } else { //条件に合わない場合 return false; } s.push_back(nextPosition); } } return true; } int main() { for (int N; scanf("%d", &N) == 1 && N;) { positionToTile.clear(); for (int i = 0; i < N; ++i) { int x, y; char direction; scanf("%d%d %c", &x, &y, &direction); ++x; ++y; const pair current(x, y); const pair opposite(x + ((direction == 'x') ? 1 : 0), y + ((direction == 'y') ? 1 : 0)); TILE tile; tile.state = SUSPENSION; tile.opposite = opposite; positionToTile.insert(make_pair(current, tile)); TILE tileOpposite; tileOpposite.state = SUSPENSION; tileOpposite.opposite = current; positionToTile.insert(make_pair(opposite, tileOpposite)); } bool ok = true; for (map, TILE>::iterator it = positionToTile.begin(); it != positionToTile.end() && ok; ++it) { const pair& position = it->first; const TILE& tile = it->second; if (tile.state == SUSPENSION) { ok = check(position.first, position.second); } } if (ok) { printf("Yes\n"); } else { printf("No\n"); } } }