結果
問題 | No.208 王将 |
ユーザー |
![]() |
提出日時 | 2016-01-08 16:51:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 136 ms / 1,000 ms |
コード長 | 1,316 bytes |
コンパイル時間 | 3,692 ms |
コンパイル使用メモリ | 77,628 KB |
実行使用メモリ | 41,376 KB |
最終ジャッジ日時 | 2024-10-09 16:29:19 |
合計ジャッジ時間 | 7,436 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 23 |
ソースコード
public class No_208 { static boolean straight(int x, int y) { if (x == 0 || y == 0 || Math.abs(x) == Math.abs(y)) { return true; } else { return false; } } static String direction(int x, int y) { if (x == 0) { if (y > 0) return "N"; else return "S"; } else if (y == 0) { if (x > 0) return "E"; else return "W"; } else if (x == y) { if (x > 0) return "NE"; else return "SW"; } else { if (x > y) return "SE"; else return "NW"; } } static boolean inTheWay(String dir, int Y, int fuY) { switch (dir) { case "N": case "E": case "S": case "W": return false; case "NE": case "NW": if (Y > fuY) return true; else return false; case "SE": case "SW": if (Y < fuY) return true; else return false; } return false; } public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int X, Y, fuX, fuY; X = sc.nextInt(); Y = sc.nextInt(); fuX = sc.nextInt(); fuY = sc.nextInt(); int step = Math.max(X, Y); if (straight(X, Y) && straight(fuX, fuY)) { String dir = direction(X, Y); if (dir.equals(direction(fuX, fuY))) { if (inTheWay(dir, Y, fuY)) { step += 1; } } } System.out.println(step); sc.close(); } }