結果
| 問題 |
No.61 リベリオン
|
| コンテスト | |
| ユーザー |
data9824
|
| 提出日時 | 2015-06-18 23:40:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 5,000 ms |
| コード長 | 1,304 bytes |
| コンパイル時間 | 413 ms |
| コンパイル使用メモリ | 60,716 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 16:14:22 |
| 合計ジャッジ時間 | 893 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 |
ソースコード
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int x, int y) {
do {
if (x < y) {
swap(x, y);
}
x = x % y;
} while (x > 0);
return y;
}
int main() {
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int w, h, d, mx, my, hx, hy, vx, vy;
cin >> w >> h >> d >> mx >> my >> hx >> hy >> vx >> vy;
int divisor;
if (vx == 0) {
divisor = abs(vy);
} else if (vy == 0) {
divisor = abs(vx);
} else {
divisor = gcd(abs(vx), abs(vy));
}
vx /= divisor;
vy /= divisor;
int vxSign = vx >= 0 ? 1 : -1;
int vySign = vy >= 0 ? 1 : -1;
vx = abs(vx) % (2 * w);
if (vx > w) {
vx = -(2 * w - vx);
}
vx *= vxSign;
vy = abs(vy) % (2 * h);
if (vy > h) {
vy = -(2 * h - vy);
}
vy *= vySign;
int x = hx, y = hy;
int vvx = vx, vvy = vy;
bool hit = false;
for (long long t = 0; t < d * divisor; ++t) {
x += vvx;
y += vvy;
if (x < 0) {
x = -x;
vvx = -vvx;
} else if (x > w) {
x = w - (x - w);
vvx = -vvx;
}
if (y < 0) {
y = -y;
vvy = -vvy;
} else if (y > h) {
y = h - (y - h);
vvy = -vvy;
}
if (x == mx && y == my) {
hit = true;
break;
}
if (x == hx && y == hy && vvx == vx && vvy == vy) {
break;
}
}
cout << (hit ? "Hit" : "Miss") << endl;
}
return 0;
}
data9824