結果
問題 |
No.240 ナイト散歩
|
ユーザー |
![]() |
提出日時 | 2016-01-24 13:32:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,005 bytes |
コンパイル時間 | 646 ms |
コンパイル使用メモリ | 64,704 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-07 21:19:20 |
合計ジャッジ時間 | 1,637 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include<stdio.h> #include<iostream> #include<queue> using namespace std; struct P { int x = 0; int y = 0; }; int main() { int jump = 3; int knight = 8; int count = jump; int knight_jump[8][2] = { {1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1},{-2,1},{-1,2} }; bool ans = false; queue<P*> q; queue<P*> openList; P* input_p = new P; P* start = new P; cin >> input_p->x >> input_p->y; openList.push(start); q.push(start); P* now; int open = 0; while (count > 0) { open = q.size(); for (int i = 0; i < open; i++) { now = q.front(); q.pop(); for (int i = 0; i < knight; i++) { P* point = new P; point->x = now->x + knight_jump[i][0]; point->y = now->y + knight_jump[i][1]; openList.push(point); q.push(point); } } --count; } while (!openList.empty()) { now = openList.front(); ans |= (now->x == input_p->x && now->y == input_p->y); openList.pop(); delete now; } delete input_p; cout << (ans ? "YES" : "NO") << endl; return 0; }