結果

問題 No.61 リベリオン
ユーザー mamekinmamekin
提出日時 2015-02-21 00:19:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 1,428 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 90,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:19:01
合計ジャッジ時間 1,485 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 49 ms
5,376 KB
testcase_04 AC 50 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int gcd(int a, int b){
    while(b != 0){
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

bool solve()
{
    int w, h, n, mx, my, x, y, vx, vy;
    cin >> w >> h >> n >> mx >> my >> x >> y >> vx >> vy;

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

    n = min(n, (w + 1) * (h + 1) * 4);
    while(--n >= 0){
        x += vx;
        y += vy;

        while((vx < 0 && x <= 0) || (vx > 0 && x >= w)){
            if(x <= 0)
                x = -x;
            else
                x = 2 * w - x;
            vx *= -1;
        }
        while((vy < 0 && y <= 0) || (vy > 0 && y >= h)){
            if(y <= 0)
                y = -y;
            else
                y = 2 * h - y;
            vy *= -1;
        }

        if(x == mx && y == my)
            return true;
    }

    return false;
}

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

    while(--q >= 0){
        if(solve())
            cout << "Hit" << endl;
        else
            cout << "Miss" << endl;
    }

    return 0;
}
0