結果

問題 No.61 リベリオン
ユーザー ふーらくたるふーらくたる
提出日時 2016-08-13 03:23:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 868 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 55,132 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:20:23
合計ジャッジ時間 1,068 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 53 ms
5,376 KB
testcase_04 AC 53 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:22: warning: ‘cy’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |         if (cx == mx && cy == my) cout << "Hit" << endl;
      |             ~~~~~~~~~^~~~~~~~~~~
main.cpp:34:9: warning: ‘cx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |         if (cx == mx && cy == my) cout << "Hit" << endl;
      |         ^~

ソースコード

diff #

#include <iostream>
using namespace std;

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int main() {
    int q;
    cin >> q;

    while (q--) {
        int w, h, d, mx, my, hx, hy, vx, vy;

        cin >> w >> h >> d >> mx >> my >> hx >> hy >> vx >> vy;

        int g = gcd(abs(vx), abs(vy));
        vx /= g; vy /= g; d *= g;

        // 状態が(W+1)*(H+1)*4しかない
        int cx, cy;
        for (int t = 1; t <= min(d, (h+1)*(w+1)*4); t++) {
            cx = abs(hx + t * vx);
            cy = abs(hy + t * vy);

            cx %= 2 * w;
            if (cx > w) cx = 2 * w - cx;
            cy %= 2 * h;
            if (cy > h) cy = 2 * h - cy;

            if (cx == mx && cy == my) break;
        }
        if (cx == mx && cy == my) cout << "Hit" << endl;
        else cout << "Miss" << endl;
    }
    return 0;
}
0