結果

問題 No.61 リベリオン
ユーザー tempura-samatempura-sama
提出日時 2016-04-14 17:55:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 1,314 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 55,004 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:19:57
合計ジャッジ時間 946 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 72 ms
5,376 KB
testcase_04 AC 74 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;

#define WH 15

#define CYCLE(x) ((x) * 2)

struct Vector2 {
	int x, y;
};

int n;
int w, h;
int tl;
Vector2 mami;
Vector2 homu;
Vector2 v;

inline int gcd(int x, int y)
{
	if ( x == y ) { return x; }
	if ( x < y ) { return gcd(y, x); }
	while ( x > y ) {
		x -= y;
	}
	return gcd(y, x);
}

inline int abs(int x)
{
	return x < 0 ? -x : x;
}

inline int pos(int p, int m, int l, int t)
{
	p = abs(p + m * t);
	p = p % CYCLE(l);
	p = p <= l ? p : CYCLE(l) - p;
	return p;
}

int hit_test()
{
	// 時間Dが10^8と多いので時間かかりそうだが、
	// 部屋サイズW,Hが15までと狭いので、W*H秒もあれば同じ軌道を飛ぶようになる。

	if ( v.x == 0 ) {
		tl *= abs(v.y); v.y = 1;
	}
	else if ( v.y == 0 ) {
		tl *= abs(v.x); v.x = 1;
	}
	else {
		int g = gcd(abs(v.x), abs(v.y));
		tl *= g; v.x /= g; v.y /= g;
	}

	for ( int i = 0; i < WH * WH * 4 && i < tl; i++ ) {
		int x = pos(homu.x, v.x, w, i + 1);
		int y = pos(homu.y, v.y, h, i + 1);
		if ( x == mami.x && y == mami.y ) {
			return 1;
		}
	}

	return 0;
}

int main()
{
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> w >> h >> tl;
		cin >> mami.x >> mami.y >> homu.x >> homu.y >> v.x >> v.y;
		cout << (hit_test() ? "Hit" : "Miss") << endl;
	}

	return 0;
}
0