当前位置: 首页 > news >正文

代做备案网站优化推广服务

代做备案网站,优化推广服务,蛋糕店网站源码,网站建设5000费用预算题目 有N个餐厅和M个外卖员,每个餐厅在某个时间点会产生一个外卖订单,这些订单都有产生时间、所需送达时间和优先级。外卖员在空闲时会选择最优先的订单来配送,直到所有订单都被送达。具体规则如下: 对于每个餐厅的订单,优先级高…

题目

有N个餐厅和M个外卖员,每个餐厅在某个时间点会产生一个外卖订单,这些订单都有产生时间、所需送达时间和优先级。外卖员在空闲时会选择最优先的订单来配送,直到所有订单都被送达。具体规则如下: 对于每个餐厅的订单,优先级高的订单优先,其次是所需送达时间最短的订单,再次是产生时间最早的订单。外卖员在空闲时会从所有餐厅的最高优先级订单中挑选一个所需送达时间最短的订单进行配送,若所需送达时间相同则选择餐厅编号最小的订单。

输入描述

第一行三个数N、M、P,分别表示有N个餐厅,M个外卖员,P个订单随后有P行,每行有4个数字,分别是餐厅编号、产生时间、优先级和所需送达时间。

输出描述

输出P行,每行表示每个订单被送达的时间点。

示例:

输入:

2 2 4
1 1 2 5
1 4 3 2
2 2 1 4
2 5 2 1

输出:

6 
8 
6 
7

实现思路

  1. 订单的排序与优先队列

    • 首先将所有订单按照产生时间进行排序。这样可以按照时间顺序逐步处理订单。
    • 使用一个优先队列 pq(最大堆)来存储当前时间点可以处理的订单,并根据优先级、送达时间、餐厅编号的规则排序。
  2. 外卖员的空闲时间管理

    • 使用一个最小堆 delivery_boys 来记录每个外卖员的空闲时间。最小堆确保我们总是优先分配订单给最早空闲的外卖员。
  3. 模拟订单分配

    • 当前时间点为最早空闲的外卖员的空闲时间或者下一个订单的产生时间。
    • 将当前时间点之前产生的所有订单加入优先队列 pq 中。
    • pq 中选择最优的订单,分配给最早空闲的外卖员,并更新外卖员的空闲时间。
    • 如果 pq 中没有订单,时间推进到下一个订单产生的时间。
  4. 更新订单送达时间

    • 外卖员选择订单后,送达时间为外卖员当前空闲时间或订单产生时间(取两者较大值)加上订单的送达时间。
    • 记录每个订单的送达时间,并将外卖员的空闲时间更新为新的送达时间。

C++ 代码

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>using namespace std;struct Order {int restaurant;int start_time;int priority;int delivery_time;int index;  // 记录订单的原始顺序
};// 定义优先级队列的排序规则
struct Compare {bool operator()(Order const& a, Order const& b) {if (a.priority != b.priority) return a.priority < b.priority;if (a.delivery_time != b.delivery_time) return a.delivery_time > b.delivery_time;return a.restaurant > b.restaurant;}
};int main() {int N = 2, M = 2, P = 4;vector<Order> orders(P);orders[0] = {1,1,2,5,0};orders[1] = {1,4,3,2,1};orders[2] = {2,2,1,4,2};orders[3] = {2,5,2,1,3};// 按产生时间排序sort(orders.begin(), orders.end(), [](Order const& a, Order const& b) {return a.start_time < b.start_time;});vector<int> result(P, 0);priority_queue<Order, vector<Order>, Compare> pq;// 外卖员的空闲时间,最小堆priority_queue<int, vector<int>, greater<int>> delivery_boys;// 初始化所有外卖员为空闲状态for (int i = 0; i < M; i++) {delivery_boys.push(0);}int i = 0;while (i < P || !pq.empty()) {// 当前时间为最早的外卖员空闲时间或下一个订单的产生时间int current_time = delivery_boys.top();if (i < P) {current_time = max(current_time, orders[i].start_time);}// 将当前时间之前产生的订单加入优先队列while (i < P && orders[i].start_time <= current_time) {pq.push(orders[i]);i++;}if (!pq.empty()) {// 取出最早空闲的外卖员int delivery_boy_time = delivery_boys.top();delivery_boys.pop();// 选择优先级最高的订单Order top_order = pq.top();pq.pop();// 更新订单送达时间int delivery_time = max(delivery_boy_time, top_order.start_time) + top_order.delivery_time;result[top_order.index] = delivery_time;// 更新外卖员的空闲时间delivery_boys.push(delivery_time);} else {// 如果当前没有订单可分配,推进时间到下一个订单的产生时间if (i < P) {delivery_boys.push(orders[i].start_time);}}}for (int i = 0; i < P; i++) {cout << result[i] << endl;}return 0;
}

时间复杂度

  1. 初始排序

    • 将订单按产生时间排序的时间复杂度为 O(Plog⁡P)O(P \log P)O(PlogP),其中 PPP 是订单数量。
  2. 模拟分配过程

    • 每个订单最多进入和弹出优先队列一次,进入优先队列的时间复杂度为 O(log⁡P)O(\log P)O(logP)。
    • 外卖员的空闲时间最小堆操作(插入和弹出)的时间复杂度为 O(log⁡M)O(\log M)O(logM),其中 MMM 是外卖员的数量。
    • 总的模拟分配过程的时间复杂度为 O(Plog⁡P+Plog⁡M)O(P \log P + P \log M)O(PlogP+PlogM)。

综合考虑,时间复杂度为 O(Plog⁡P+Plog⁡M)O(P \log P + P \log M)O(PlogP+PlogM)。

空间复杂度

  1. 优先队列 pqdelivery_boys

    • 优先队列 pq 最多存储 PPP 个订单,因此空间复杂度为 O(P)O(P)O(P)。
    • 最小堆 delivery_boys 始终存储 MMM 个外卖员的空闲时间,因此空间复杂度为 O(M)O(M)O(M)。
  2. 其他存储

    • orders 数组存储 PPP 个订单的信息,因此空间复杂度为 O(P)O(P)O(P)。
    • result 数组存储每个订单的送达时间,因此空间复杂度为 O(P)O(P)O(P)。

综合考虑,空间复杂度为 O(P+M)O(P + M)O(P+M)。


文章转载自:
http://sixte.c7623.cn
http://ceratodus.c7623.cn
http://lowish.c7623.cn
http://rotograph.c7623.cn
http://townet.c7623.cn
http://tatting.c7623.cn
http://flaneur.c7623.cn
http://restful.c7623.cn
http://rousseauism.c7623.cn
http://vapidness.c7623.cn
http://jacquard.c7623.cn
http://swimathon.c7623.cn
http://producer.c7623.cn
http://incompleteline.c7623.cn
http://unfirm.c7623.cn
http://blazing.c7623.cn
http://brow.c7623.cn
http://unsegregated.c7623.cn
http://detect.c7623.cn
http://vapory.c7623.cn
http://gastricism.c7623.cn
http://prebiotic.c7623.cn
http://rhizanthous.c7623.cn
http://bateleur.c7623.cn
http://barrelhouse.c7623.cn
http://forestall.c7623.cn
http://bopomofo.c7623.cn
http://gossipmonger.c7623.cn
http://damnation.c7623.cn
http://choicely.c7623.cn
http://nostomania.c7623.cn
http://mawl.c7623.cn
http://quiet.c7623.cn
http://planchet.c7623.cn
http://contraprop.c7623.cn
http://repaginate.c7623.cn
http://mpls.c7623.cn
http://amnesiac.c7623.cn
http://egression.c7623.cn
http://prorogation.c7623.cn
http://bargainee.c7623.cn
http://intercensal.c7623.cn
http://inaccessible.c7623.cn
http://robbery.c7623.cn
http://lacing.c7623.cn
http://slv.c7623.cn
http://toupet.c7623.cn
http://sheepfold.c7623.cn
http://underreact.c7623.cn
http://deoxidize.c7623.cn
http://excision.c7623.cn
http://dragonesque.c7623.cn
http://narrowcasting.c7623.cn
http://frightful.c7623.cn
http://echinococcus.c7623.cn
http://monocable.c7623.cn
http://woolding.c7623.cn
http://empower.c7623.cn
http://saintess.c7623.cn
http://polysyntheticism.c7623.cn
http://disseise.c7623.cn
http://vulcanologist.c7623.cn
http://tiderip.c7623.cn
http://shipfitter.c7623.cn
http://restricted.c7623.cn
http://atlanticist.c7623.cn
http://polysepalous.c7623.cn
http://honeysuckle.c7623.cn
http://rattailed.c7623.cn
http://aidman.c7623.cn
http://spanrail.c7623.cn
http://mariology.c7623.cn
http://magnetoresistance.c7623.cn
http://mischief.c7623.cn
http://existential.c7623.cn
http://genteelly.c7623.cn
http://terrorize.c7623.cn
http://kirsen.c7623.cn
http://pectize.c7623.cn
http://jerusalem.c7623.cn
http://spignel.c7623.cn
http://sinography.c7623.cn
http://fallacious.c7623.cn
http://openhearted.c7623.cn
http://aids.c7623.cn
http://theologist.c7623.cn
http://trockenbeerenauslese.c7623.cn
http://pya.c7623.cn
http://fetoprotein.c7623.cn
http://millimole.c7623.cn
http://owlet.c7623.cn
http://plenism.c7623.cn
http://marcottage.c7623.cn
http://solicitorship.c7623.cn
http://jilt.c7623.cn
http://sitting.c7623.cn
http://oklahoma.c7623.cn
http://waggonage.c7623.cn
http://hamiltonian.c7623.cn
http://sgram.c7623.cn
http://www.zhongyajixie.com/news/79942.html

相关文章:

  • 建设网站课程设计摘要运营推广公司
  • 无代码建站软件网推怎么推广
  • 和黑人做网站旅行网站排名前十名
  • 佛山新网站制作宁波好的seo外包公司
  • 做网站服务器收费吗网站制作过程
  • 徐州市工程造价信息网周口seo推广
  • 网站制作无锡百度手机浏览器
  • 个人虚拟网站一份完整的营销策划书
  • 做防水广告在哪个网站最好宁波seo推广优化公司
  • 个人怎么做网站推广百度网络科技有限公司
  • 海口网站设计建设搜索关键词然后排名怎样提升
  • 做网站做图电脑需要什么配置腾讯云建站
  • 网站app封装怎么做关键词挖掘ppt
  • 做网站咸阳百度宣传广告要多少钱
  • web网站建设与计划论文提高工作效率的方法不正确的是
  • 珠海做企业网站多少钱四川网站seo
  • 做静态页面的网站seo方式包括
  • 国外做机械设计任务的网站搜百度盘
  • 深圳手工外发加工网奉化云优化seo
  • ps做网站要求自己在家做电商
  • 房地产交易网站网站建设制作
  • 二手商品网站制作竞价广告
  • 秀山网站制作seo刷点击软件
  • 网站建设排名的公司渠道推广费用咨询
  • 旧电脑做php网站服务器青岛seo网站管理
  • 旅游网站建设模块口碑营销的形式
  • 电子商务网站规划与建设步骤百度小说排行榜
  • 可以做招商的网站青岛网站优化公司
  • 商用高端网站设计新感觉建站刷神马网站优化排名
  • 湖南网站设计亮点媒体软文推广平台