結果
| 問題 | No.61 リベリオン | 
| コンテスト | |
| ユーザー |  ふーらくたる | 
| 提出日時 | 2016-08-13 03:23:10 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 48 ms / 5,000 ms | 
| コード長 | 868 bytes | 
| コンパイル時間 | 369 ms | 
| コンパイル使用メモリ | 56,908 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-13 16:15:11 | 
| 合計ジャッジ時間 | 849 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 4 | 
コンパイルメッセージ
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;
      |         ^~
            
            ソースコード
#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;
}
            
            
            
        