华为od统一考试B卷【需要打开多少监视器】C语言 实现

您所在的位置:网站首页 车位最少需要多少宽 华为od统一考试B卷【需要打开多少监视器】C语言 实现

华为od统一考试B卷【需要打开多少监视器】C语言 实现

#华为od统一考试B卷【需要打开多少监视器】C语言 实现| 来源: 网络整理| 查看: 265

2023华为od机试C卷【堆内存申请】Java 实现

qq_42003397: 没看while循环里面的自己写了个逻辑 [code=java] // 分配空间足够且最接近申请内存大小空间 // 取每一个足够的区间,找到最小的开始节点 // 处理开始区间 第一个0到start的长度,需判断是否从0开始 int from = 0; int to = list.get(0)[0]; List result = new ArrayList(); if (to != from && to - from > apply) { result.add(new int[]{to - from, from}); } for (int i = 0; i < length - 1; i++) { from = list.get(i)[1]; to = list.get(i + 1)[0]; // 取相邻区间的补集,判断是否大于申请区间 // 大于即满足条件 if (to - from > apply) { result.add(new int[]{to - from, from + 1}); } } // 处理结束区间 最后一个end到99的长度,需判断是否占满 from = list.get(length - 1)[1]; to = 99; if (to != from && to - from > apply) { result.add(new int[]{to - from, from + 1}); } if (!result.isEmpty()) { // 排序取最小的区间段即可 Collections.sort(result, Comparator.comparingInt(o -> o[0])); [/code]

2023华为od机试C卷【最优的投资方式】Java 实现

2401_86012662: [code=java] System.out.println(stringJoiner); [/code]

2023华为od机试C卷【最优的投资方式】Java 实现

2401_86012662: [code=java] buyj = Math.min(asset - buyi, maxInput[j]); } else { if (maxInput[j] >= asset) { continue; } buyj = maxInput[j]; buyi = Math.min(asset - buyj, maxInput[j]); } int currentProfit = buyi * returnRate[i] + buyj * returnRate[j]; if (currentProfit > maxProfit) { choseCount = 2; Arrays.fill(result2, 0); result2[i] = buyi; result2[j] = buyj; } } } } int[] temp = choseCount == 1 ? result1 : result2; StringJoiner stringJoiner = new StringJoiner(" "); for (int i = 0; i < temp.length; i++) { stringJoiner.add(String.valueOf(temp[i])); } [/code]

2023华为od机试C卷【最优的投资方式】Java 实现

2401_86012662: [code=java] int buy = Math.min(asset, maxInput[i]); int currentProfit = buy * returnRate[i]; if (currentProfit > maxProfit) { Arrays.fill(result1, 0); result1[i] = buy; maxProfit = currentProfit; } } } int[] result2 = new int[productCount]; Arrays.fill(result2, 0); for (int i = 0; i < productCount; i++) { for (int j = 0; j < productCount; j++) { if (i == j) { continue; } if (riskCount[i] + riskCount[j] returnRate[j]) { if (maxInput[i] >= asset) { continue; } buyi = maxInput[i]; [/code]

2023华为od机试C卷【最优的投资方式】Java 实现

2401_86012662: 按博主思路分类讨论: [code=java] package od; import java.util.Arrays; import java.util.Scanner; import java.util.StringJoiner; /** * @author zwj * @date 2024/7/8 */ public class N25 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int productCount = in.nextInt(); int asset = in.nextInt(); int risk = in.nextInt(); in.nextLine(); //回报率 int[] returnRate = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); //风险 int[] riskCount = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); //最大投资额度 int[] maxInput = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int choseCount = 1; int maxProfit = 0; int[] result1 = new int[productCount]; Arrays.fill(result1, 0); for (int i = 0; i < productCount; i++) { if (riskCount[i]



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3