http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2000
#include <iostream> #include <string> using namespace std; int main (int argc, char * const argv[]) { // insert code here... int N; while (cin >> N) { if (N == 0) { break; } int h_x[N]; int h_y[N]; bool kekka[N]; //入力 for (int i=0; i < N; i++) { cin >> h_x[i]; cin >> h_y[i]; //結果用フラグ kekka[i] = false; } int M; cin >> M; char hougaku[M]; int hougaku_num[M]; for (int i=0; i < M; i++) { cin >> hougaku[i]; cin >> hougaku_num[i]; } //初期位置 int x = 10; int y = 10; //計算 for (int i=0; i < M; i++) { switch (hougaku[i]) { case 'N': //北の場合(y方向に+) for (int j = 0; j < hougaku_num[i]; j++) { y++; //宝を取ってるかの確認 for (int k=0; k < N; k++) { if (x == h_x[k] && y == h_y[k]) { kekka[k] = true; } } } break; case 'E': //東の場合(x方向に+) for (int j = 0; j < hougaku_num[i]; j++) { x++; //宝を取ってるかの確認 for (int k=0; k < N; k++) { if (x == h_x[k] && y == h_y[k]) { kekka[k] = true; } } } break; case 'S': //南の場合(y方向に-) for (int j = 0; j < hougaku_num[i]; j++) { y--; //宝を取ってるかの確認 for (int k=0; k < N; k++) { if (x == h_x[k] && y == h_y[k]) { kekka[k] = true; } } } break; case 'W': //西の場合(x方向に-) for (int j = 0; j < hougaku_num[i]; j++) { x--; //宝を取ってるかの確認 for (int k=0; k < N; k++) { if (x == h_x[k] && y == h_y[k]) { kekka[k] = true; } } } break; default: break; } } bool finish = false; for (int j=0; j < N; j++) { if (!kekka[j]) { cout << "No" << endl; finish = true; break; } } if (!finish) { cout << "Yes" << endl; } } return 0; }