Mysterious Gems
テーブルを用意して,宝石をばら撒いて,ロボットで掘り返しました.
#include <iostream> using namespace std; void dis(int field[][22]) { for(int i = 0; i < 22; i++) { for(int j = 0; j < 22; j++) { if(i == 10 && j == 10) cout << "* "; else cout << field[i][j] << " "; } cout << endl; } } int main() { // ファイル FILE *fp_in, *fp_out; fp_in = fopen("a.in", "r"); fp_out = fopen("a.out", "w"); while(true) { int field[22][22]; // 探索領域 for(int i = 0; i < 22; i++) { for(int j = 0; j < 22; j++) { field[i][j] = 0; } } // // 入力 // int n; fscanf(fp_in, "%d ", &n); cout << n << endl; if(n == 0) break; for(int i = 0; i < n; i++) { int x, y; fscanf(fp_in, "%d %d ", &x, &y); field[y][x] += 1; cout << x << " " << y << endl; } int m; int x = 10, y = 10; // 自分の位置 fscanf(fp_in, "%d ", &m); cout << m << endl; for(int i = 0; i < m; i++) { char ori; // 方向 int dis; // 距離 fscanf(fp_in, "%c %d ", &ori, &dis); cout << ori << " " << dis << endl; // // 処理 // // 移動方向を決める int dx, dy; // 移動方向 switch(ori) { case 'N': dx = 0; dy = 1; break; case 'E': dx = 1; dy = 0; break; case 'S': dx = 0; dy = -1; break; case 'W': dx = -1; dy = 0; break; } // 動いた座標をほりかえす(+1 for(int j = 0; j < dis; j++) { x += dx; y += dy; field[y][x]++; } } // 見つけた宝石(2)の数を数える int get = 0; for(int i = 0; i < 22; i++) { for(int j = 0; j < 22; j++) { if(field[i][j] == 2) get++; } } cout << get << endl; if(n == get) { cout << "Yes" << endl; fprintf(fp_out, "Yes\n"); } else { cout << "No" << endl; fprintf(fp_out, "No\n"); } } fclose(fp_in); fclose(fp_out); return 0; }