結果

問題 No.48 ロボットの操縦
ユーザー なおなお
提出日時 2014-10-12 01:25:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,407 bytes
コンパイル時間 1,137 ms
コンパイル使用メモリ 51,224 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 23:51:21
合計ジャッジ時間 1,606 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定解法: 場合分け

#include <iostream>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define RREP(i, n)          for(int(i)=(n)-1;(i)>=0;--(i))
void rc(int v,int mn,int mx){if(v<mn||mx<v){cerr<<"error"<<endl;}}

const int MAX = 1000000000;

int ceil(int A, int B){ return (A+B-1)/B; }
int main(){
    int X,Y,L;
    cin >> X >> Y >> L;
    rc(X,-MAX,MAX); rc(Y,-MAX,MAX); rc(L,1,MAX);

    if(X < 0) X = -X;

    int res = 0;
    if(Y >= 0){
        res += ceil(Y,L);
        if(X) res += ceil(X,L) + 1;
    } else {
        res = ceil(-Y,L) + ceil(X,L) + 2;
    }

    cout << res << endl;
    return 0;
}

/* 解説 
向きを変えるのは多くとも2回あれば、任意の座標に到達することができる。
X座標は回転の向きが変わるだけなので、正に正規化してしまって問題ない。
向きを変える回数は、
・目的地のY座標が正でかつX座標が0の場合、0回
・目的地のY座標が正でかつX座標が0以外の場合、1回
・目的地のY座標が負の場合のみ、2回
必要となる。

Y>=0,X=0の場合、前進のみで          ceil(Y/L)
Y>=0,X>0の場合、前進+回転+前進で  ceil(Y/L)  + ceil(X/L) + 1
Y<0の場合、回転+前進+回転+前進で ceil(-Y,L) + ceil(X/L) + 2

※ceilは小数点以下切り上げ

*/
0