关注
三个for循环,注意判断边界,然后就过了。。但是第二题怎么做都超时,希望有人贴一下解法! import java.util.*;
public class Main{
public void process(){
Scanner sc = new Scanner(System.in);
String pen;
String box;
String price;
String[] penStArr;
String[] boxStArr;
String[] priceStArr;
int colorPen;
int whitePen;
int colorA;
int whiteB;
int whiteC;
int colorD;
int x;
int y;
int z;
int sum1;
int sum2;
int sum3;
while(sc.hasNext()){
pen = sc.nextLine();
box = sc.nextLine();
price = sc.nextLine();
colorPen = Integer.parseInt(pen.split(" ")[0]);
whitePen = Integer.parseInt(pen.split(" ")[1]);
colorA = Integer.parseInt(box.split(" ")[0]);
whiteB = Integer.parseInt(box.split(" ")[1]);
whiteC = Integer.parseInt(box.split(" ")[2]);
colorD = Integer.parseInt(box.split(" ")[3]);
x = Integer.parseInt(price.split(" ")[0]);
y = Integer.parseInt(price.split(" ")[1]);
z = Integer.parseInt(price.split(" ")[2]);
int bound1 = colorPen/colorD;
int bound2 = whitePen/whiteC;
int bound3 = (colorPen/colorA > whitePen/whiteB)? whitePen/whiteB : colorPen/colorA;
int finalSum = 0;
int tempSum = 0;
for(int i = 0; i<= bound1; i++){
for(int j = 0; j<= bound2; j++){
for(int m = 0; m<= bound3; m++){
if((i*colorD + m*colorA) > colorPen || (j*whiteC+m*whiteB) > whitePen){
break;
}
tempSum = i*z + j*y + m*x;
finalSum = tempSum > finalSum ? tempSum : finalSum;
}
}
}
System.out.println(finalSum);
}
}
public static void main(String[] args){
Main m = new Main();
m.process();
}
}
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
- 1... 进大厂是因为老家找不到工作9587
- 2... 我父母让我忍受所有工作上的欺辱9107
- 3... 【Offer帮选】专家大佬在线接单!发帖即享免费1V1抉择指导8348
- 4... 双9Java0基础➡秋招4×大厂offer,这一年我到底干了什么?7589
- 5... wxg和字节flow咋选6932
- 6... 要不是有我,你们早就在一起了5204
- 7... 滴滴日常一面速通(附面筋,已OC)4319
- 8... 月薪多少才能过上"体面生活"3113
- 9... 学院本什么时候能上岸啊,唉3000
- 10... 快手员工自费给+2庆生?太带派了烙铁2463
正在热议
更多
# 职场中那些令人叹为观止的八卦 #
12248次浏览 156人参与
# 你找工作想离家近 or 离家远? #
8808次浏览 164人参与
# 百度秋招 #
45583次浏览 364人参与
# 我的职场社死时刻 #
9955次浏览 107人参与
# 如何拒绝/反向PUA #
83122次浏览 372人参与
# 你父母给过你哪些不靠谱的职场建议? #
8482次浏览 138人参与
# 腾讯音乐秋招 #
423404次浏览 4741人参与
# 秋招吐槽大会 #
48600次浏览 435人参与
# 哪些公司开始补录了 #
9947次浏览 119人参与
# 那些年,我收到的‘奇葩’回复 #
5708次浏览 59人参与
# 职场中对你有帮助的书 #
23531次浏览 213人参与
# 你秋招最后悔的选择 #
8561次浏览 69人参与
# 租房前辈的忠告 #
274685次浏览 7199人参与
# XX请雇我工作 #
7272次浏览 73人参与
# 秋招你经历过哪些无语的事 #
5537次浏览 60人参与
# 月薪多少能在一线城市生存 #
93428次浏览 677人参与
# 假如你的老板掉河里,你的工作能为他做什么 #
40000次浏览 402人参与
# 通信硬件知识分享 #
39434次浏览 527人参与
# 你觉得机械有必要实习吗 #
66906次浏览 481人参与
# 交通银行工作体验 #
21107次浏览 69人参与
# 中科曙光工作体验 #
5437次浏览 23人参与
# 秋招疯了,看什么都像offer #
8826次浏览 99人参与


海康威视公司福利 1262人发布