結果
問題 |
No.208 王将
|
ユーザー |
![]() |
提出日時 | 2015-05-15 23:01:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,031 bytes |
コンパイル時間 | 379 ms |
コンパイル使用メモリ | 46,336 KB |
実行使用メモリ | 13,752 KB |
最終ジャッジ日時 | 2024-07-06 04:13:07 |
合計ジャッジ時間 | 2,960 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 TLE * 1 -- * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf ( "%d %d" , &target.x , &target.y ); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:31:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf ( "%d %d" , &wall.x , &wall.y ); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <queue> #include <vector> #include <cstdio> using namespace std; struct Position { int x; int y; }; struct InnerData { Position pos; int cost; }; typedef queue<InnerData> InnerDataQueue; typedef vector<Position> PositionVector; Position MakePosition ( int x , int y ); int main ( void ) { Position target; Position wall; scanf ( "%d %d" , &target.x , &target.y ); scanf ( "%d %d" , &wall.x , &wall.y ); InnerData idst; idst.pos.x = 0; idst.pos.y = 0; idst.cost = 0; PositionVector history; InnerDataQueue idq; InnerData id , idnext; idq.push ( idst ); int AlreadyScanned; while ( idq.empty() == false ) { id = idq.front (); idq.pop (); if ( ( id.pos.x == wall.x ) && ( id.pos.y == wall.y ) ) continue; if ( ( id.pos.x == target.x ) && ( id.pos.y == target.y ) ) { printf ( "%d\n" , id.cost ); break; } AlreadyScanned = 0; for (unsigned int i = 0; i < history.size (); i++ ) { if ( ( history [ i ].x == id.pos.x ) && ( history [ i ].y == id.pos.y ) ) { AlreadyScanned = 1; break; } } if ( AlreadyScanned == 1 )continue; history.push_back ( id.pos ); idnext.cost = id.cost + 1; //左上 idnext.pos = MakePosition ( id.pos.x - 1 , id.pos.y - 1 ); idq.push ( idnext ); //上 idnext.pos = MakePosition ( id.pos.x , id.pos.y - 1 ); idq.push ( idnext ); //右上 idnext.pos = MakePosition ( id.pos.x + 1 , id.pos.y - 1 ); idq.push ( idnext ); //左 idnext.pos = MakePosition ( id.pos.x - 1 , id.pos.y ); idq.push ( idnext ); //右 idnext.pos = MakePosition ( id.pos.x + 1 , id.pos.y ); idq.push ( idnext ); //左下 idnext.pos = MakePosition ( id.pos.x - 1 , id.pos.y + 1 ); idq.push ( idnext ); //下 idnext.pos = MakePosition ( id.pos.x , id.pos.y + 1 ); idq.push ( idnext ); //右下 idnext.pos = MakePosition ( id.pos.x + 1 , id.pos.y + 1 ); idq.push ( idnext ); } return 0; } Position MakePosition ( int x , int y ) { Position pos; pos.x = x; pos.y = y; return pos; }