题解:AtCoder AT_awc0007_a Selection of Delivery Trucks
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】AtCoderA - Selection of Delivery Trucks【题目描述】Takahashi is a delivery planning manager at a shipping company. He needs to select exactly1 11truck out ofN NNdelivery trucks and assign it to a delivery task.高桥是一家货运公司的送货路线规划经理。他需要从N NN辆送货卡车中恰好选择1 11辆并将其分配至一项送货任务。Each trucki ii(1 ≤ i ≤ N 1 \leq i \leq N1≤i≤N) has a fuel efficiency coefficientE i E_iEi. A truck with a larger fuel efficiency coefficient consumes more fuel to travel the same distance.每辆卡车i ii1 ≤ i ≤ N 1 ≤ i ≤ N1≤i≤N具有一个燃油效率系数E i E_iEi。燃油效率系数越大的卡车行驶相同距离消耗的燃料越多。The delivery route consists ofM MMsegments, and the distance of thej jj-th segment (1 ≤ j ≤ M 1 \leq j \leq M1≤j≤M) isC j C_jCj. The selected truck will travel allM MMsegments. The fuel consumed when trucki iitravels thej jj-th segment isE i × C j E_i \times C_jEi×Cj.送货路线包含M MM个路段第j jj个路段1 ≤ j ≤ M 1 ≤ j ≤ M1≤j≤M的距离为C j C_jCj。被选中的卡车将行驶全部M MM个路段。当卡车i ii行驶第j jj个路段时消耗的燃料为E i × C j E_i × C_jEi×Cj。The total fuel consumption when trucki iiis selected is当选中卡车i ii时总燃料消耗量为∑ j 1 M E i × C j \displaystyle \sum_{j1}^{M} E_i \times C_jj1∑MEi×CjFind the minimum total fuel consumption when exactly1 11truck is chosen from theN NNtrucks to minimize the total fuel consumption.求从N NN辆卡车中恰好选择1 11辆以最小化总燃料消耗量时的最小总燃料消耗量。【输入】N NNM MME 1 E_1E1E 2 E_2E2… \ldots…E N E_NENC 1 C_1C1C 2 C_2C2… \ldots…C M C_MCMThe first line contains an integerN NNrepresenting the number of trucks and an integerM MMrepresenting the number of segments in the delivery route, separated by a space.The second line containsN NNintegersE 1 , E 2 , … , E N E_1, E_2, \ldots, E_NE1,E2,…,ENrepresenting the fuel efficiency coefficients of each truck, separated by spaces.The third line containsM MMintegersC 1 , C 2 , … , C M C_1, C_2, \ldots, C_MC1,C2,…,CMrepresenting the distance of each segment, separated by spaces.【输出】Print the minimum fuel consumption on a single line.【输入样例】3 4 5 3 7 2 4 1 3【输出样例】30【解题思路】【算法标签】#模拟#【代码详解】#includebits/stdc.husingnamespacestd;#defineintlonglongintn,m;// n: 第一个数组长度m: 第二个数组长度signedmain(){cinnm;// 读入两个数组的长度intminn1e9;// 初始化最小值用于存储第一个数组的最小值for(inti1;in;i){intx;cinx;// 读入第一个数组的元素minnmin(minn,x);// 更新最小值}intsum0;// 初始化总和用于存储第二个数组的和for(inti1;im;i){intx;cinx;// 读入第二个数组的元素sumx;// 累加总和}coutminn*sumendl;// 输出第一个数组最小值与第二个数组总和的乘积return0;}【运行结果】3 4 5 3 7 2 4 1 3 30
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2566505.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!