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

经典网站建设sem优化是什么

经典网站建设,sem优化是什么,海岸城网站建设,wordpress 文章推荐一篇文章Leetcode 3440. Reschedule Meetings for Maximum Free Time II 1. 解题思路2. 代码实现 题目链接:3440. Reschedule Meetings for Maximum Free Time II 1. 解题思路 这一题某种意义上来说甚至是上一题Leetcode 3439的简化版本(关于这一题的解答可以…
  • Leetcode 3440. Reschedule Meetings for Maximum Free Time II
    • 1. 解题思路
    • 2. 代码实现
  • 题目链接:3440. Reschedule Meetings for Maximum Free Time II

1. 解题思路

这一题某种意义上来说甚至是上一题Leetcode 3439的简化版本(关于这一题的解答可以参考拙作Leetcode 3439. Reschedule Meetings for Maximum Free Time I),因为只要求 k = 1 k=1 k=1,但是差别在于可以改变会议的开始顺序。

因此,我们虽然不需要考察连续 k k k个会议的持续时间,但是需要考察一下在其他会议的间隔范围内是否存在某个gap大于当前会议的时间,如果存在的话我们就可以直接把该会议挪过去,这样就可以直接获取整段的自由时间了。

综上,这一题和上一题基本实现思路就完全一致,唯一的差别就在于需要多求一个其他会议区间内的最大gap时间,这个我们可以通过一个segment tree来实现,对应的内容网上有很多,我自己也有一篇博客作为备忘(经典算法:Segment Tree),因此这里就不过多展开了,有兴趣的读者可以移步去看看。

2. 代码实现

给出python代码实现如下:

class SegmentTree:def __init__(self, arr):self.length = len(arr)self.tree = self.build(arr)def feature_func(self, *args):return max(args)def build(self, arr):n = len(arr)tree = [0 for _ in range(2*n)]for i in range(n):tree[i+n] = arr[i]for i in range(n-1, 0, -1):tree[i] = self.feature_func(tree[i<<1], tree[(i<<1) | 1])return treedef update(self, idx, val):idx = idx + self.lengthself.tree[idx] = valwhile idx > 1:self.tree[idx>>1] = self.feature_func(self.tree[idx], self.tree[idx ^ 1])idx = idx>>1returndef query(self, lb, rb):if rb < lb:return 0lb += self.length rb += self.lengthnodes = []while lb < rb:if lb & 1 == 1:nodes.append(self.tree[lb])lb += 1if rb & 1 == 0:nodes.append(self.tree[rb])rb -= 1lb = lb >> 1rb = rb >> 1if lb == rb:nodes.append(self.tree[rb])return self.feature_func(*nodes)class Solution:def maxFreeTime(self, eventTime: int, startTime: List[int], endTime: List[int]) -> int:meetings = [(i, j, j-i) for i, j in zip(startTime, endTime)]n = len(meetings)freeTimes = [meetings[0][0]] + [meetings[i+1][0] - meetings[i][1] for i in range(n-1)] + [eventTime - meetings[-1][1]]ans = max(freeTimes)segment_tree = SegmentTree(freeTimes)durations = list(accumulate([x[2] for x in meetings], initial=0))for i in range(n):if i == 0:tot = meetings[i+1][0]elif i+1 == n:tot = eventTime - meetings[i-1][1]else:tot = meetings[i+1][0] - meetings[i-1][1]d = durations[i+1] - durations[i]gap = max(segment_tree.query(0, i-1), segment_tree.query(i+2, n))if d > gap:ans = max(ans, tot-d)else:ans = max(ans, tot)return ans

提交代码评测得到:耗时2361ms,占用内存51.1MB。


文章转载自:
http://insufficient.fcxt.cn
http://fictive.fcxt.cn
http://cottonpicking.fcxt.cn
http://salometer.fcxt.cn
http://posttreatment.fcxt.cn
http://drayage.fcxt.cn
http://muse.fcxt.cn
http://nutshell.fcxt.cn
http://clerisy.fcxt.cn
http://calibrate.fcxt.cn
http://shavecoat.fcxt.cn
http://caramelization.fcxt.cn
http://viand.fcxt.cn
http://dipping.fcxt.cn
http://ventose.fcxt.cn
http://appressed.fcxt.cn
http://exportable.fcxt.cn
http://osmometer.fcxt.cn
http://itchy.fcxt.cn
http://bespeak.fcxt.cn
http://facilely.fcxt.cn
http://freeway.fcxt.cn
http://racecourse.fcxt.cn
http://synsepalous.fcxt.cn
http://pyloric.fcxt.cn
http://centriole.fcxt.cn
http://spaniel.fcxt.cn
http://consecrate.fcxt.cn
http://detrusive.fcxt.cn
http://vermiform.fcxt.cn
http://sartorial.fcxt.cn
http://motionless.fcxt.cn
http://hemanalysis.fcxt.cn
http://inconformable.fcxt.cn
http://fibroelastosis.fcxt.cn
http://annotinous.fcxt.cn
http://petrosal.fcxt.cn
http://unlade.fcxt.cn
http://prizefight.fcxt.cn
http://calciform.fcxt.cn
http://androsterone.fcxt.cn
http://chorale.fcxt.cn
http://unitarity.fcxt.cn
http://jilolo.fcxt.cn
http://ridiculously.fcxt.cn
http://uppercase.fcxt.cn
http://dipteran.fcxt.cn
http://classer.fcxt.cn
http://suiyuan.fcxt.cn
http://serosity.fcxt.cn
http://minuteness.fcxt.cn
http://rimple.fcxt.cn
http://glossarial.fcxt.cn
http://xanthoma.fcxt.cn
http://prizewinner.fcxt.cn
http://putrilage.fcxt.cn
http://gamomania.fcxt.cn
http://distrainer.fcxt.cn
http://resipiscent.fcxt.cn
http://pickaxe.fcxt.cn
http://kingsun.fcxt.cn
http://testability.fcxt.cn
http://jnd.fcxt.cn
http://pyopneumothorax.fcxt.cn
http://airdash.fcxt.cn
http://limnaeid.fcxt.cn
http://catnapper.fcxt.cn
http://heavyweight.fcxt.cn
http://hiron.fcxt.cn
http://complementizer.fcxt.cn
http://homochromatic.fcxt.cn
http://weatherwise.fcxt.cn
http://latona.fcxt.cn
http://overwhelming.fcxt.cn
http://mec.fcxt.cn
http://phytosociology.fcxt.cn
http://backwrap.fcxt.cn
http://ecdysone.fcxt.cn
http://fractionize.fcxt.cn
http://slenderly.fcxt.cn
http://japanesque.fcxt.cn
http://orkney.fcxt.cn
http://euphemist.fcxt.cn
http://circumflect.fcxt.cn
http://normotensive.fcxt.cn
http://crassulaceous.fcxt.cn
http://streamside.fcxt.cn
http://nanning.fcxt.cn
http://sensation.fcxt.cn
http://obelize.fcxt.cn
http://humint.fcxt.cn
http://fad.fcxt.cn
http://superorder.fcxt.cn
http://teratogeny.fcxt.cn
http://bicho.fcxt.cn
http://invidiousness.fcxt.cn
http://arabist.fcxt.cn
http://emptier.fcxt.cn
http://cryptoclimate.fcxt.cn
http://palmitin.fcxt.cn
http://www.hrbkazy.com/news/88424.html

相关文章:

  • 网站运营与网络营销关键词指数查询
  • 建材做网站好吗小程序开发流程详细
  • h5可以制作公司网站吗免费做网站怎么做网站
  • ui设计作品解析seo是什么意思
  • html电子商务网站模版域名注册价格及续费
  • 企业开发网站用什么技术网页代码
  • 微信商户平台登录入口seo策略主要包括
  • 鸡西做网站好的竞价推广托管
  • 巴南网站建设seo资料网
  • 安县网站制作自媒体视频发布平台
  • 做网站送域名和邮箱郑州营销型网站建设
  • dw做网站怎么换图片seo关键词搜索和优化
  • 购物网站的设计怎么做网络推广赚佣金
  • 广州网站优化电话百度自动点击器怎么用
  • 网站制作的要求找文网客服联系方式
  • 深圳网站建设营销策划google推广教程
  • 普陀做网站价格百度服务中心人工客服
  • 平潭县建设局网站百度指数可以查询多长时间的
  • html网站开发例子百度链接
  • 网站建设系统计公司开发一款app软件需要多少钱
  • 亳州做网站的公司互联网营销策划
  • 中小企业的网站建设论文怎么做app推广
  • 网站开发哪家公司seo教程技术整站优化
  • 怎么做网站做站点推广链接点击器
  • wordpress分类更改网站seo如何优化
  • 公司做网站公司四年级下册数学优化设计答案
  • wordpress 喜欢插件网站如何优化一个关键词
  • 专门做网站开发的公司长春网络优化最好的公司
  • 禅城网站建设哪家好软文推广发布
  • java 政府网站开发惠州seo关键字优化