import java.util.Scanner; public class AmberChallenge { static final int MAX_WIND_FIELDS = 5; static int[] windFields = new int[MAX_WIND_FIELDS]; static int windFieldCount = 0; static int[] windRings = new int[MAX_WIND_FIELDS]; static int windRingCount = 0; static boolean canReachDestination(int d, int h, int x, int y, int t, int currentDistance, int currentHeight, int speedMultiplier, int windRingRemainingTime) { // 如果安柏落水或者飞过了目的地,返回false if (currentHeight <= 0 || currentDistance > d) { return false; } // 如果安柏到达了目的地,返回true if (currentDistance == d && currentHeight == 0) { return true; } // 如果安柏在风环效果中 if (windRingRemainingTime > 0) { // 继续前进,保持当前的速度倍率 if (canReachDestination(d, h, x, y, t, currentDistance + x * speedMultiplier, currentHeight - y, speedMultiplier, windRingRemainingTime - 1)) { return true; } } else { // 如果不在风环效果里,检查是否可以进入一个风环 for (int i = 0; i < windRingCount; i++) { if (currentDistance == windRings[i]) { // 进入风环,速度倍率设置为2,重新设置风环效果时间 if (canReachDestination(d, h, x, y, t, currentDistance, currentHeight, 2, t)) { return true; } } } } // 检查是否可以进入风场,如果可以,将高度设置为最大值 for (int i = 0; i < windFieldCount; i++) { if (currentDistance == windFields[i]) { if (canReachDestination(d, h, x, y, t, currentDistance + x, h, speedMultiplier, windRingRemainingTime)) { return true; } } } // 没有进入风场也没有风环效果,正常飞行一次 return canReachDestination(d, h, x, y, t, currentDistance + x, currentHeight - y, speedMultiplier, windRingRemainingTime); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCases = scanner.nextInt(); while (testCases-- > 0) { int d = scanner.nextInt(); // 目的地水平距离 int h = scanner.nextInt(); // 初始高度 int x = scanner.nextInt(); // 水平飞行速度 int y = scanner.nextInt(); // 垂直下降速度 int t = scanner.nextInt(); // 风环效果时间 windFieldCount = scanner.nextInt(); for (int i = 0; i < windFieldCount; i++) { windFields[i] = scanner.nextInt(); } windRingCount = scanner.nextInt(); for (int i = 0; i < windRingCount; i++) { windRings[i] = scanner.nextInt(); } boolean result = canReachDestination(d, h, x, y, t, 0, h, 1, 0); System.out.println(result ? "YES" : "NO"); } scanner.close(); } }
点赞 1

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
牛客网
牛客企业服务