2017 8.25 阿里巴巴校招 在线笔试题
2017-08-26 14:37
357 查看
2017 8.25 阿里巴巴校招 在线笔试题
选择(40min)
略
编程题(80min)
1.天猫 物流,海关问题
关键字:盒子大小、每盒总价值小于2000
求 最少盒子数
public class NewTest {
在快递公司干线运输的车辆使用中,存在着单边车和双边车的两种使用场景,例如 北京中心-杭州中心,两个分拨中心到彼此的单量对等,则可以开双边车(即同一辆车可以往返对开),而当两个中心的对发单量不对等时,则会采用单边车,并且双边车的成本是低于单边车的,即将两辆对开的单边车合并为一辆往返的双边车是能够节省运力成本的
单边车优化原则:
将单边车优化的规则进行可抽象为以下三种(A,B,C均表示分拨中心):
规则-1: A-B单边车,B-A单边车 优化方案:将A-B和B-A的两辆单边车合并为双边;
规则-2: A-B单边车,B-C单边车,C-A单边车 优化方案:将A-B、B-C、C-A的三辆单边车优化为一辆环形往返车;
规则-3: A-B单边车,C-A单边车,B、C同省 优化方案:当B、C同省,将A-B、C-A两辆单边优化为一辆环形往返
问题如下:
以某快递公司的实际单边车数据为例(线路ID编码;出分拨中心; 出分拨中心所在省;到达分拨中心;到达分拨中心所在省;车型;),进行优化,优化的规则参照以上,并且优先级依次降低,合并的时候需要考虑车型(分为17.5m和9.6m两种):1、相同车型才能进行合并;2、两辆同方向的9.6m可以与一辆17.5m的对开车型合并优化 说明:优化输出结果按照规则分类,例如rule1: 2016120001+2016120002表示将单边车线路ID编码为2016120001和2016120002按照规则1合并优化
已输入字数: 1837 / 10000 运行 编程说明 +
选择(40min)
略
编程题(80min)
1.天猫 物流,海关问题
关键字:盒子大小、每盒总价值小于2000
求 最少盒子数
public class NewTest {
/** 请完成下面这个process函数,实现题目要求的功能 **/ /** 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^ **/ private static int process() { int amount=0,maxlength=0,maxhight=0;maxwidth=0,j=0; int sumlength= boxTemplate.length; int sumheight= boxTemplate.height; int sumwidth = boxTemplate.width; for(int i=0;i<itemNum;i++){ for(int j=i;j<itemNum;j++){ if(item[i].length<=boxTemplate.length&&maxlength<=boxTemplate.length){ if(item[i].height<=boxTemplate.height&&maxhight<=boxTemplate.height){ if(item[i].width<=boxTemplate.widthmaxwidth<=boxTemplate.width){ if(item[j].price<=2000&&amount<=2000){ amount+=items[j].price; maxlength+=items[j].length; maxhight+=items[j].height; maxwidth+=items[j].width; sumlength-=items[j].length;items[j].length=0; sumlength-=item[i].height;items[j].height=0; sumlength-=item[i].width;items[j].width=0;} } } }}boxMinNum++;sumlength=boxTemplate.length;sumheight=boxTemplate.height;sumwidth=boxTemplate.width;}return boxMinNum;} public static void main(String args[]){ Scanner scanner = new Scanner(System.in); boxTemplate.price = CUSTOMS_LIMIT_MONEY_PER_BOX; while (scanner.hasNext()){ boxTemplate.length = scanner.nextInt(); boxTemplate.width = scanner.nextInt(); boxTemplate.height = scanner.nextInt(); int itemNum = scanner.nextInt(); items = new Model[itemNum]; for(int i=0; i<itemNum; i++){ Model item = new Model(); item.price = scanner.nextInt(); item.length = scanner.nextInt(); item.width = scanner.nextInt(); item.height = scanner.nextInt(); items[i] = item; } long startTime = System.currentTimeMillis(); boxMinNum = Integer.MAX_VALUE; System.out.println (process()); } } }
在快递公司干线运输的车辆使用中,存在着单边车和双边车的两种使用场景,例如 北京中心-杭州中心,两个分拨中心到彼此的单量对等,则可以开双边车(即同一辆车可以往返对开),而当两个中心的对发单量不对等时,则会采用单边车,并且双边车的成本是低于单边车的,即将两辆对开的单边车合并为一辆往返的双边车是能够节省运力成本的
单边车优化原则:
将单边车优化的规则进行可抽象为以下三种(A,B,C均表示分拨中心):
规则-1: A-B单边车,B-A单边车 优化方案:将A-B和B-A的两辆单边车合并为双边;
规则-2: A-B单边车,B-C单边车,C-A单边车 优化方案:将A-B、B-C、C-A的三辆单边车优化为一辆环形往返车;
规则-3: A-B单边车,C-A单边车,B、C同省 优化方案:当B、C同省,将A-B、C-A两辆单边优化为一辆环形往返
问题如下:
以某快递公司的实际单边车数据为例(线路ID编码;出分拨中心; 出分拨中心所在省;到达分拨中心;到达分拨中心所在省;车型;),进行优化,优化的规则参照以上,并且优先级依次降低,合并的时候需要考虑车型(分为17.5m和9.6m两种):1、相同车型才能进行合并;2、两辆同方向的9.6m可以与一辆17.5m的对开车型合并优化 说明:优化输出结果按照规则分类,例如rule1: 2016120001+2016120002表示将单边车线路ID编码为2016120001和2016120002按照规则1合并优化
已输入字数: 1837 / 10000 运行 编程说明 +
public class Bus { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); List<UnilateralLine> lineList = new ArrayList<UnilateralLine>(); while (scanner.hasNextLine()) { String[] options = scanner.nextLine().split(";"); if (options.length < 5) { break; } lineList.add(new UnilateralLine(options[0], options[1], options[2], options[3], options[4], options[5])); } scanner.close(); // wirte your code here List<String> result = calculateUnilateral(lineList); for (String str : result) { System.out.println(str); } } public static List<String> calculateUnilateral(List<UnilateralLine> lineList) { List<String> result = new ArrayList<String>(); int i,k,j; boolean flag=true; for(i=0;i<lineList.size()&&flag!=false;i++){ k=i+1;j=k; //rule 1: if(lineList.get(i)!=null){ for(;k<lineList.size();k++){ if(lineList.get(k)!=null){ if(lineList.get(i).sCen==lineList.get(k).eCen&&lineList.get(k).sCen==lineList.get(i).eCen){ if(lineList.get(i).tType==lineList.get(k).tType){ result.set(i, (lineList.get(i).id+lineList.get(k).id)); lineList.remove(i);lineList.remove(k); flag=false;break; }} }} if(flag=false){ flag=true;break;} k=i+1;} //rule 2: else if(lineList.get(i)!=null){ while(lineList.get(k)!=null&&k<lineList.size()){ if(lineList.get(i).sCen==lineList.get(k).eCen){ while(j<lineList.size()){ if(lineList.get(k).sCen==lineList.get(j).eCen){ if(lineList.get(j).sCen==lineList.get(i).eCen){ if(judge(lineList.get(i).tType,lineList.get(k).tType,lineList.get(j).tType)!= false){ result.set(i, (lineList.get(i).id+lineList.get(k).id+lineList.get(j).id)); lineList.remove(i);lineList.remove(k);lineList.remove(j); flag=false;break;} }}j++;}} if(flag=false){ break;}k++;} if(flag=false){ flag=true;break;} } //rule 3: else if(lineList.get(i)!=null){ while(k<lineList.size()){ if(lineList.get(i).sCen==lineList.get(k).eCen&&lineList.get(i).eCen!=lineList.get(k).sCen&&lineList.get(i).ePro==lineList.get(k).sPro){ if(lineList.get(i).tType==lineList.get(0).tType){ result.set(i, (lineList.get(i).id+lineList.get(k).id)); lineList.remove(i);lineList.remove(k); flag=false;break;} } } } } return result; } private static boolean judge(String tType, String tType2, String tType3) { String a="9.6m"; if(tType==tType2&&tType2==tType3){return true;} else{ if(tType==tType2&&tType.equals(a)){return true;} if(tType==tType3&&tType.equals(a)){return true;} if(tType2==tType3&&tType2.equals(a)){return true;} } return false; } public static class UnilateralLine { private String id; private String sCen;//出发分拨 private String sPro;//出发省 private String eCen;//到达分拨 private String ePro;//到达省 //9.6m/17.5m private String tType;//车型 public UnilateralLine(String id, String sCen, String sPro, String eCen, String ePro,String tType) { this.id = id;this.sCen = sCen;this.sPro = sPro;this.eCen = eCen;this.ePro = ePro;this.tType = tType;} public String getId() {return id;} public void setId(String id) {this.id = id;} public String getSCen() {return sCen;} public void setSCen(String ePro) {this.ePro = ePro;} public String getSPro() {return sPro;} public void setSPro(String sPro) {this.sPro = sPro;} public String getECen() {return eCen;} public void setECen(String eCen) {this.eCen = eCen;} public String getEPro() {return ePro;} public void setEPro(String ePro) {this.ePro = ePro;} public String getTType() {return tType;} public void setTType(String tType) {this.tType = tType;} } }
相关文章推荐
- 2017阿里巴巴校招在线笔试——货架格子编号
- 2015届阿里巴巴校招研发在线笔试题
- 下列不属于hash碰撞解决方法的是()。----阿里巴巴2015校招研发在线笔试题
- 2015 阿里巴巴 校招研发在线笔试题
- 针对外部存储器(如磁盘)上存放的程序和数据,说法正确的是()。----阿里巴巴2015校招研发在线笔试题
- 【在线笔试题解题报告系列】网易2017校招内推笔试之编程题【持续更新】
- 阿里巴巴2017校招C++岗位在线编程题-求集合D的最大值,最小值和元素个数三者之和
- [2017腾讯校招在线笔试题]
- 阿里巴巴2017校招C++岗位在线编程题-RNA嵌套
- 阿里巴巴2015秋季校招(客户端开发工程师岗位)在线笔试题
- 阿里巴巴2015校招研发在线笔试题
- 爱奇艺2017校招-Java开发-在线算法笔试题-NIM博弈问题,牛牛羊羊吃草
- 网易2017校招内推在线笔试编程题3
- 去哪儿网2017校招在线笔试(前端工程师)编程题及JavaScript代码
- 2015阿里巴巴校招在线笔试题
- 阿里巴巴2016校招在线笔试附加题(C++研发)
- 2017阿里巴巴前端在线笔试题
- 有多少个进程被 fork 出来了?----阿里巴巴2015校招研发在线笔试题
- 阿里巴巴校招2017前端笔试题目 -- 原生js/html5 实现一个路由
- 百度2017校招java研发在线笔试