2012年7月7日土曜日

AOJ Volume20 2000: Misterious Games


/*************************
*  2012/07/07            *
*  AOJ_Volume20_2000     *
*  Misterious_Gems       *
*  crane                 *
**************************/

#include<iostream>
using namespace std;

#define FIELD 21
bool field[FIELD][FIELD];

int main(){

    int n; //宝石の個数
    while(cin >> n, n){
        for(int i=0; i<FIELD; i++)
            for(int j=0; j<FIELD; j++)
                field[i][j] = false;

        /*--宝石の位置--*/
        int xi, yi;
        for(int i=0; i<n; i++){
            cin >> xi >> yi;
            field[yi][xi] = true;
        }   

        int m;    //命令の個数
        cin >> m;

        char dj;
        int lj;
        int x = 10, y = 10;            //ロボット降下位置
        for(int i=0; i<m; i++){
            cin >> dj >> lj;        //命令取得
            while(lj--){
                switch (dj){
                case 'N':
                    y++;
                    break;
                case 'E':
                    x++;
                    break;
                case 'S':
                    y--;
                    break;
                case 'W':
                    x--;
                    break;
                }

                if(field[y][x]){
                    n--;
                    field[y][x] = false;
                }
            }
        }   
        if(n == 0) cout << "Yes" << endl;
        else       cout << "No" << endl;
    }
}

0 件のコメント:

コメントを投稿