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

爱站网站建设语言都有什么

爱站,网站建设语言都有什么,珠海网站制作价格,陆良县住房和城乡建设局网站滑动窗口#xff08;尺取法#xff09; 算法含义#xff1a; 在解决关于区间特性的题目时保存搜索区间左右端点#xff0c;然后根据实际要求不断更新左右端点位置的算法 时间复杂度#xff1a; O ( n ) O(n) O(n) 空间复杂度#xff1a; O ( 1 ) O(1) O(1) 在历年真题…滑动窗口尺取法 算法含义 在解决关于区间特性的题目时保存搜索区间左右端点然后根据实际要求不断更新左右端点位置的算法 时间复杂度 O ( n ) O(n) O(n) 空间复杂度 O ( 1 ) O(1) O(1) 在历年真题中滑动窗口主要有求追偿不重复子串和模拟优先队列求区间最值两个作用 一、求最长不重复字串 不重复子串字符串的字串中不包含重复字符的字串 from collections import defaultdicts input() n len(s) # 建立一个字典存储各个元素在窗口中出现的次数 d defaultdict(int) ans 0 # 确定窗口左端 left 0 for right in range(n):# 如果发现窗口中已经有s[right]将left右移直到窗口中不存在s[right]while d[s[right]] 0:# 更新字典d[s[left]] - 1left 1ans max(ans, right-left1)print(ans)二、模拟优先队列求区间最值 滑动窗口研究区间的性质可以用于模拟优先队列从而高效求出区间内的最大值和最小值 例题 1: 附近最小蓝桥杯第14届省模拟赛 问题描述: 小蓝有一个序列 a [ 1 ] , a [ 2 ] , . . . , a [ n ] a[1],a[2],...,a[n] a[1],a[2],...,a[n]。给定一个正整数 k请问对于每一个 1 到 n 之间的正整数i a [ i − k ] , a [ i − k 1 ] , . . . , a [ i k ] a[i−k],a[i−k1],...,a[ik] a[i−k],a[i−k1],...,a[ik] 这 2k1 个数中的最小值是多少 当某个下标超过 1 到 n 的范围时数不存在求最小值时只取存在的那些值。 输入格式: 输入的第一行包含一整数 n第二行包含 n 个整数分别表示 a [ 1 ] , a [ 2 ] , . . . , a [ n ] a[1],a[2],...,a[n] a[1],a[2],...,a[n]。第三行包含一个整数 k 输出格式 输出一行包含 n 个整数分别表示对于每个序号求得的最小值。 代码示例 # 滑动窗口 优先队列 n int(input()) a [int(i) for i in input().split()] k int(input()) # 在数组右边补k个一定不是最小值的数以免分类讨论 a a [a[n-1]1]*k d k*21 # 窗口宽度 ans [] q [] # 递增的优先队列 # 注意i是滑动窗口的右端点 for i in range(nk):# 如果队列不为空将所有大于当前元素的队尾元素出队while q and a[q[-1]] a[i]:q.pop()# 将新元素的下标入队q.append(i)# 检查队头元素是否在新区间范围内if i - q[0] d-1:q.pop(0)# 将队头元素记录下来if i k:ans.append(a[q[0]])# print answer print( .join(list(map(str, ans))))例题 2: 子矩阵蓝桥杯第14届省赛真题 问题描述: 给定一个n x m(n行m列)的矩阵。设一个矩阵的价值为其所有数中的最大值和最小值的乘积。求给定矩阵的所有大小为 a x b (a行b列)的子矩阵的价值的和。答案可能很大你只需要输出答案对 998244353 取模后的结果。 输入格式: 输入的第一行包含四个整数分别表示nmab相邻整数之间使用一个空格分隔。接下来 n行每行包含m个整数相邻整数之间使用一个空格分隔表示矩阵中的每个数 A i j A_{ij} Aij​。 输出格式 输出一行包含一个整数表示答案。 # 利用滑动窗口模拟优先队列从而将搜索每一个区间中最值的时间复杂度从O(n*n)优化为O(n) MOD 998244353 def get_max(nums,step):# the variable called step store the size of intervalq []max_list []for i in range(len(nums)):while q and nums[q[-1]] nums[i]:# when the end element of prior-quee is small than the new element# pop out the end elementq.pop(-1)# the list store the index of every number because it is more convenient to find # out whether the index is out of the interval or not q.append(i)# when the first element is out of the range of interval, pop it outif q[0] i-step:q.pop(0)# when the queue has been built, add the first element into the answer listif i step-1:max_list.append(nums[q[0]])return max_list # using the same theory,we can find out the minist number def get_min(nums,step):q []min_list []for i in range(len(nums)):while q and nums[q[-1]] nums[i]:q.pop(-1)q.append(i)if q[0] i-step:q.pop(0)if i step-1:min_list.append(nums[q[0]])return min_list # similarly,we can calculate out the sum of all the numbers in the interval def get_sum(nums,step):sum_list []temp 0# the pointer called i is actually the right pointer# the left pointers value is i-step1for i in range(len(nums)):if i step - 1:temp nums[i]elif i step-1:temp nums[i]sum_list.append(temp)else:temp - nums[i-step]temp nums[i]sum_list.append(temp)return sum_list# the main part of the algorithm # firstly,use the function to find out all the lines extremum n,m,a,b map(int,input().split()) matrix [] for i in range(n):matrix.append([int(j) for j in input().split()]) # zip the row m_max_one [] m_min_one [] for i in range(n):m_max_one.append(get_max(matrix[i], b))m_min_one.append(get_min(matrix[i], b)) # transpose the temporary matrix and zip again # the result is the collection of extremum matrix m_max_two [[0]*n for i in range(len(m_max_one[0]))] m_min_two [[0]*n for i in range(len(m_min_one[0]))] for i in range(len(m_max_one[0])):for j in range(len(m_max_one)):m_max_two[i][j] m_max_one[j][i]m_min_two[i][j] m_min_one[j][i] # zip the col m_max [] m_min [] for i in range(len(m_max_two)):m_max.append(get_max(m_max_two[i], a))m_min.append(get_min(m_min_two[i], a)) # calculate the sum of all the sub_matrixs value res 0 for i in range(len(m_max)):for j in range(len(m_max[0])):res m_max[i][j]*m_min[i][j]res % MOD print(res)
http://www.pierceye.com/news/690586/

相关文章:

  • 用自己的电脑做网站需要备案吗wordpress rss教程
  • 洛阳网站搭建江西网站建设价格低
  • 戴尔网站建设的目的济宁哪里有做网站的
  • 给单位做网站需要多少钱wordpress手机编辑
  • 网站开发实验报告总结怎样搭建微网站
  • 诸暨有哪些制作网站公司代理品牌
  • jsp mysql 网站开发响应网官方网站
  • 小白网站建设教程服务器域名多少钱
  • 网站建设预付款比例网站平台建设公司经营范围
  • 付费阅读网站代码CMS源码就可以做网站吗
  • 企业网站用视频做首页wordpress 多主题插件下载
  • 阿里巴巴网官方网站新公司在哪做网站
  • 邢台专业做网站报价做一门户网站价格
  • 中山企业手机网站建设设计方案翻译
  • 江苏省品牌专业群建设专题网站wordpress 返利 插件
  • 建设部网站官网设计排版网站
  • 企业网站建设应避免数据孤岛网站建设费入何科目
  • wordpress数据量大网站访问石家庄网站建设招商
  • 公司核名在哪个网站免费申请无限流量卡
  • 做网站和网页的目的和作用是什么山西2地又检出阳性
  • 自助网站建设推广优化策略wordpress中文采集插件
  • 网站开发及运营成本做网站 公司 个体
  • 永久免费建站地址苏州h5网站建设价钱
  • 室内设计网站网站建设中请稍后再访问
  • 十堰网站开发培训编程软件手机
  • 南京网站优化推广微网站缺点
  • 大连零基础网站建设培训哪里有固安县建设局网站
  • 怎么制作网站首页培训心得体会总结简短
  • 商务网站建设 模板长春高端品牌网站建设
  • 做网站比较便宜办公资源网