結果

問題 No.61 リベリオン
ユーザー myantamyanta
提出日時 2017-05-11 10:41:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,138 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 43,520 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:20:47
合計ジャッジ時間 987 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 33 ms
5,376 KB
testcase_04 AC 32 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |                         scanf("%d%d%d%d%d%d%d%d%d", &w, &h, &d, &mx, &my, &hx, &hy, &vx, &vy);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<vector>


using namespace std;

using vi=vector<int>;
using vvi=vector<vi>;


int gcd(int a, int b)
{
	int c;
	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


int laparound(int x, int m)
{
	return (x%m+m)%m;
}


int main(void)
{
	int q, w, h, d, mx, my, hx, hy, vx, vy;
	int x, y, i, j, t;
	vvi f;

	while(scanf("%d", &q)==1)
	{
		for(i=0;i<q;i++)
		{
			scanf("%d%d%d%d%d%d%d%d%d", &w, &h, &d, &mx, &my, &hx, &hy, &vx, &vy);
//printf("w=%d h=%d d=%d vx=%d vy=%d\n", w, h, d, vx, vy);
			if(vx==0)
			{
				t=abs(vy);
			}
			else if(vy==0)
			{
				t=abs(vx);
			}
			else
			{
				t=gcd(abs(vx), abs(vy));
			}
			vx/=t;
			vy/=t;
			d*=t;
//printf("  w=%d h=%d d=%d vx=%d vy=%d\n", w, h, d, vx, vy);

			f.clear();
			f.resize(2*h);
			for(auto& fe: f) fe.resize(2*w);

			x=hx;
			y=hy;
			for(j=0;j<d;j++)
			{
				x=laparound(x+vx, 2*w);
				y=laparound(y+vy, 2*h);
				if(f[y][x]) break;
				f[y][x]=1;
			}
			int mx2=2*w-mx;
			int my2=2*h-my;
			int hit=0;
			if(f[my][mx] || f[my][mx2] || f[my2][mx] || f[my2][mx2]) hit=1;
			printf("%s\n", hit?"Hit":"Miss");
		}
	}

	return 0;
}
0