結果

問題 No.61 リベリオン
ユーザー scachescache
提出日時 2014-11-10 01:00:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,458 bytes
コンパイル時間 6,539 ms
コンパイル使用メモリ 79,264 KB
実行使用メモリ 64,828 KB
最終ジャッジ日時 2023-08-30 02:59:00
合計ジャッジ時間 9,122 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,072 KB
testcase_01 AC 131 ms
55,796 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 126 ms
55,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.util.Scanner;

public class Main61 {
	public static void main(String[] args) {
		Main61 p = new Main61();
	}

	public Main61() {
		Scanner sc = new Scanner(System.in);
		
		int q = sc.nextInt();
		for(int i=0;i<q;i++){
			int w = sc.nextInt();
			int h = sc.nextInt();
			int d = sc.nextInt();
			int mx = sc.nextInt();
			int my = sc.nextInt();
			int hx = sc.nextInt();
			int hy = sc.nextInt();
			int vx = sc.nextInt();
			int vy = sc.nextInt();
			
			if(solve(w, h, d, mx, my, hx, hy, vx, vy)){
				System.out.println("Hit");
			}else{
				System.out.println("Miss");
			}
		}
	}

	public boolean solve(int w, int h, int d, int mx, int my, int hx, int hy, int vx, int vy) {
		int statex = 1;
		int statey = 1;
		
		if(vx <0){
			vx = -vx;
			statex = -1;
		}
		
		if(vy <0){
			vy = -vy;
			statey = -1;
		}
		
		int curx = hx;
		int cury = hy;
		int m = Math.min(d, 4*w*h);
		for(int i=0;i<m;i++){
			curx += statex * vx;
			cury += statey * vy;
			
			while(curx > w || curx < 0){
				if(curx > w){
					statex = -1;
					curx = 2*w - curx;
				}else if(curx < 0){
					statex = 1;
					curx = - curx;
				}
			}
			while(cury >h || cury < 0){
				if(cury > h){
					statey = -1;
					cury = 2*h - cury;
				}else if(cury < 0){
					statey = 1;
					cury = - cury;
				}
			}
		
			if(curx==mx && cury==my)
				return true;
		}
		
		return false;
	}

	
}
0