关注
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
相关推荐

点赞 评论 收藏
分享
04-21 16:05
北京邮电大学 Java 点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 写给毕业5年后的自己 #
5072次浏览 105人参与
# 国央企笔面经互助 #
129913次浏览 1082人参与
# 华泰证券Fintech星战营 #
169424次浏览 196人参与
# 职场捅娄子大赛 #
324062次浏览 3297人参与
# 好好告别我的学生时代 #
48845次浏览 907人参与
# 一人一个landing小技巧 #
61246次浏览 972人参与
# 毕业季等于分手季吗 #
17754次浏览 224人参与
# 美的求职进展汇总 #
274795次浏览 1955人参与
# 海信求职进展汇总 #
65369次浏览 361人参与
# 晒一下我的毕业照 #
35207次浏览 398人参与
# 毕业后不工作的日子里我在做什么 #
172146次浏览 1521人参与
# 记录实习开销 #
31327次浏览 214人参与
# 如何缓解求职过程中的焦虑? #
8280次浏览 106人参与
# HR问:你期望的薪资是多少?如何回答 #
40393次浏览 527人参与
# 如果今天是你的last day,你会怎么度过? #
22992次浏览 199人参与
# 大学最后一个寒假,我想…… #
38447次浏览 500人参与
# 毕业租房也有小确幸 #
110229次浏览 4327人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
108570次浏览 783人参与
# 视觉/交互/设计百问百答 #
43354次浏览 428人参与
# 2022毕业即失业取暖地 #
97160次浏览 651人参与
# 材料转码还有必要吗? #
22010次浏览 135人参与