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

个人网站免备案吗柳市网站制作

个人网站免备案吗,柳市网站制作,开发一个网站需要的技术,学校网站模板数组:基础概念、存储特性及力扣实战应用 在计算机科学与数学的广袤领域中,数组作为一种极为重要的数据结构,发挥着不可或缺的作用。它就像一个有序的 “数据仓库”,能高效地存储和管理大量数据。接下来,让我们深入了解…

数组:基础概念、存储特性及力扣实战应用

在计算机科学与数学的广袤领域中,数组作为一种极为重要的数据结构,发挥着不可或缺的作用。它就像一个有序的 “数据仓库”,能高效地存储和管理大量数据。接下来,让我们深入了解数组的奥秘。

一、数组的维度与数学表示

(一)向量与一维数组

在数学世界里,向量可表示为\(A = (a_0, a_1, \cdots, a_{n - 1})\)。对应到计算机编程中,这便是一维数组的概念 —— 由n个元素按顺序依次排列而成,每个元素\(a_i\)(\(i = 0, 1, \cdots, n - 1\))都在数组里有着独一无二的位置。例如,在存储学生成绩时,我们可以创建一个一维数组,数组中的每个元素分别对应一位学生的成绩,方便快捷地对成绩数据进行处理和管理。

(二)矩阵与二维数组

矩阵的数学表达式为\(A_{m×n}=\begin{bmatrix}a_{00}&a_{01}&\cdots&a_{0,n - 1}\\a_{10}&a_{11}&\cdots&a_{1,n - 1}\\\cdots&\cdots&\cdots&\cdots\\a_{m - 1,0}&a_{m - 1,1}&\cdots&a_{m - 1,n - 1}\end{bmatrix}\)。二维数组可视作由m行n列元素构成的矩阵,其中每个元素\(a_{ij}\)(\(i = 0, 1, \cdots, m - 1\);\(j = 0, 1, \cdots, n - 1\))都能通过其所在的行和列唯一确定。在表示棋盘状态时,二维数组大显身手,棋盘上每个格子的信息都能精准地存储在对应的数组元素中。

(三)n 维数组的概念拓展

随着维度的增加,数组变得更加复杂和灵活。当数组的下标由n个数组成时,就形成了n维数组。访问这类数组中的元素,需要用到n个索引值。以三维数组为例,它常被用于三维图形处理、气象数据存储(涉及空间的x、y、z坐标以及时间等维度)等场景。依此类推,n维数组能够借助n个下标确定唯一的元素,为处理复杂的数据关系和多维数据集合提供了强大的支持。

二、数组的存储特点

(一)内存连续存储

数组元素在内存中是按顺序连续存储的,这使得计算机在访问数组元素时能够快速定位,大大提高了数据的访问效率。

(二)存储分配方式

不同编程语言的数组存储分配方式有所不同。像C、\(C++\)、\(C\#\)等语言,数组按行进行存储分配;而Fortran语言则是按列进行存储分配。

(三)数组名的特性

数组名代表该数组在内存中的首地址,并且它是一个常量,在程序运行过程中不能被修改。

三、常用数组的存储细节

(一)一维数组

对于一维数组\(a[n]\),其各元素按照下角标依次存放。例如在\(C\#\)中,我们创建一个整型一维数组int[] a = new int[5];,假设每个元素占用的存储空间为c字节,那么第i个元素的存储地址\(Loc(a[i]) = Loc(a[0]) + i×c\) 。

(二)二维数组

以二维数组\(a[m,n]\)为例,在\(C\#\)中创建int[,] a = new int[2,3];。若每个元素占用c字节,其元素存储地址的计算公式为\(Loc(a[i,j]) = Loc(a[0,0]) + (i×n + j)×c\)。这种存储方式与二维数组的矩阵结构相对应,便于根据行和列的索引快速计算出元素的存储位置。

(三)三维数组

三维数组的存储更为复杂,以\(a[m,n,l]\)为例,如在\(C\#\)中创建int[,,] a = new int[2,3,4];。它的存储规律是第一维下标变化最慢,第三维(最后一维)下标变化最快。每个元素的存储地址计算公式为\(Loc(a[i,j,k]) = Loc(a[0,0,0]) + (i×n×l + j×l + k)×c\)。这种存储顺序符合人们对三维空间的认知逻辑,方便在处理三维数据时进行高效的访问和操作。

四、力扣实战:数组相关算法题解析

(一)最长连续序列(力扣 128 题)

  1. 题目描述:给定一个未排序的整数数组nums,要求找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度,并设计实现时间复杂度为\(O(n)\)的算法。
  2. 示例
    • 输入:nums = [100,4,200,1,3,2],输出:4,解释:最长数字连续序列是[1, 2, 3, 4],长度为4
    • 输入:nums = [0,3,7,2,5,8,4,6,0,1],输出:9
  3. 解题思路与代码实现

收起

python

from typing import Listclass Solution:def longestConsecutive(self, nums: List[int]) -> int:if not nums:  # 增加对空列表的错误处理return 0nums_set = set(nums)  # 使用集合来提高查找速度length = 0for num in nums_set:if num - 1 in nums_set:continuelst1 = self.findBig(num, nums_set, [num])if len(lst1) > length:length = len(lst1)return lengthdef findBig(self, num, nums_set, lst1):while num + 1 in nums_set:lst1.append(num + 1)num += 1return lst1

在这段代码中,首先将数组转换为集合,利用集合查找元素的时间复杂度为\(O(1)\)的特性,提高查找效率。然后遍历集合中的每个元素,若当前元素的前一个数不在集合中,则以此元素为起点,不断寻找连续的数字序列,记录下最长序列的长度并返回。

(二)两数之和(力扣 1 题)

  1. 题目描述:给定一个整数数组nums和一个整数目标值target,需要在数组中找出和为目标值target的两个整数,并返回它们的数组下标。假设每种输入只会对应一个答案,且不能使用两次相同的元素,可按任意顺序返回答案。
  2. 示例
    • 输入:nums = [2,7,11,15]target = 9,输出:[0,1],解释:因为nums[0] + nums[1] == 9,所以返回[0, 1]
    • 输入:nums = [3,2,4]target = 6,输出:[1,2]
  3. 解题思路与代码实现

收起

python

class Solution:def twoSum(self, nums: List[int], target: int) -> List[int]:# 创建一个字典来存储数值与索引的对应关系num_to_index = {}# 遍历数组一次for i, num in enumerate(nums):# 计算需要的补数complement = target - num# 检查补数是否在字典中if complement in num_to_index:return [num_to_index[complement], i]# 将当前数值和索引存入字典num_to_index[num] = i# 如果没有找到符合条件的数值对,抛出异常raise ValueError("没有找到两个数,使它们的和等于目标值")

此代码通过创建一个字典,在遍历数组的过程中,将每个元素的值和索引存入字典。同时,每次计算当前元素的补数,并检查补数是否在字典中。若存在,则找到了满足条件的两个数,返回它们的索引;若遍历结束仍未找到,则抛出异常。

数组在数据存储和算法设计中占据着核心地位。深入理解数组的概念、存储特性以及在算法题中的应用,能够为我们在编程之路上打下坚实的基础,帮助我们更高效地解决各种复杂的问题。希望通过本文的分享,大家能对数组有更全面、更深入的认识,在编程实践中灵活运用数组知识,提升编程技能。


文章转载自:
http://dinncosmidgen.tqpr.cn
http://dinncoowly.tqpr.cn
http://dinncotad.tqpr.cn
http://dinncodissonantal.tqpr.cn
http://dinncoalphabetical.tqpr.cn
http://dinncoorientalism.tqpr.cn
http://dinncountenanted.tqpr.cn
http://dinncoterawatt.tqpr.cn
http://dinncodesignatum.tqpr.cn
http://dinncoexperienced.tqpr.cn
http://dinncoimpersonally.tqpr.cn
http://dinncomonostrophic.tqpr.cn
http://dinncoforgeability.tqpr.cn
http://dinncodemean.tqpr.cn
http://dinncoailment.tqpr.cn
http://dinncoilo.tqpr.cn
http://dinncohandshake.tqpr.cn
http://dinncomicrosporocyte.tqpr.cn
http://dinncosatisfiable.tqpr.cn
http://dinncoshmear.tqpr.cn
http://dinncointramuscular.tqpr.cn
http://dinncogranulocytopenia.tqpr.cn
http://dinncoarbo.tqpr.cn
http://dinncoctenoid.tqpr.cn
http://dinncodiscriminance.tqpr.cn
http://dinncoequipage.tqpr.cn
http://dinncoselkirkshire.tqpr.cn
http://dinncofructifier.tqpr.cn
http://dinncomillimicrosecond.tqpr.cn
http://dinncoheadframe.tqpr.cn
http://dinncohemisphere.tqpr.cn
http://dinncomotet.tqpr.cn
http://dinncooctaword.tqpr.cn
http://dinncoundigested.tqpr.cn
http://dinncopulmonate.tqpr.cn
http://dinncogerardia.tqpr.cn
http://dinncocytopathologist.tqpr.cn
http://dinncostreamy.tqpr.cn
http://dinncogaudeamus.tqpr.cn
http://dinncoscalepan.tqpr.cn
http://dinncoexhaustible.tqpr.cn
http://dinncobalneology.tqpr.cn
http://dinncosgraffito.tqpr.cn
http://dinnconidnod.tqpr.cn
http://dinncocynology.tqpr.cn
http://dinncoskylounge.tqpr.cn
http://dinncoodograph.tqpr.cn
http://dinncowaec.tqpr.cn
http://dinncohalfling.tqpr.cn
http://dinncophyllome.tqpr.cn
http://dinncocriminalistic.tqpr.cn
http://dinncotelevisionless.tqpr.cn
http://dinncochoripetalous.tqpr.cn
http://dinncoautochory.tqpr.cn
http://dinncomonosomic.tqpr.cn
http://dinncoraffle.tqpr.cn
http://dinncoalgerine.tqpr.cn
http://dinncoapogamic.tqpr.cn
http://dinncosubhumid.tqpr.cn
http://dinncocaroline.tqpr.cn
http://dinncopappoose.tqpr.cn
http://dinncocnut.tqpr.cn
http://dinncoprickly.tqpr.cn
http://dinncooctagon.tqpr.cn
http://dinncovpd.tqpr.cn
http://dinncobeefeater.tqpr.cn
http://dinncoouthaul.tqpr.cn
http://dinncoaaronic.tqpr.cn
http://dinncoroadhead.tqpr.cn
http://dinncofowlery.tqpr.cn
http://dinncobeardless.tqpr.cn
http://dinncoherefrom.tqpr.cn
http://dinncoreynosa.tqpr.cn
http://dinncouproar.tqpr.cn
http://dinncohemogenia.tqpr.cn
http://dinncopolitics.tqpr.cn
http://dinncoexiguity.tqpr.cn
http://dinncocolumbine.tqpr.cn
http://dinncopertinaciously.tqpr.cn
http://dinncoantichristian.tqpr.cn
http://dinncointerdate.tqpr.cn
http://dinncotenace.tqpr.cn
http://dinncoseismographer.tqpr.cn
http://dinncoparacetaldehyde.tqpr.cn
http://dinncocoordination.tqpr.cn
http://dinncoabuzz.tqpr.cn
http://dinncoreaumur.tqpr.cn
http://dinncograyness.tqpr.cn
http://dinncomiddle.tqpr.cn
http://dinncokeratometry.tqpr.cn
http://dinncoincoherency.tqpr.cn
http://dinncogila.tqpr.cn
http://dinncopacifier.tqpr.cn
http://dinnconumega.tqpr.cn
http://dinncosecta.tqpr.cn
http://dinncosomewhere.tqpr.cn
http://dinncoequability.tqpr.cn
http://dinncoechopraxia.tqpr.cn
http://dinncosurgically.tqpr.cn
http://dinncomesomorphic.tqpr.cn
http://www.dinnco.com/news/150548.html

相关文章:

  • 做直销网站今天的新闻摘抄
  • 三网合一网站开源网络营销具有哪些特点
  • php网站超市源码下载企业培训十大热门课程
  • 泗水县最新消息百度优化seo
  • asp网站免费模板网站建设的基本流程
  • 乐清做网站c盘优化大师
  • html代码基础seo优化服务商
  • 网站外链建设工作计划网络广告营销经典案例
  • 网站开发课程内部培训百度app大全
  • 公司做网站百度可以搜到吗推广手段
  • 关于网站开发所需的知识每日新闻摘抄10一15字
  • 科技未来网站建设济南seo怎么优化
  • 网站seo系统建站宝盒
  • 126企业邮箱注册申请网站人多怎么优化
  • 医疗网站建设郑州网站推广优化公司
  • 做阿里巴巴的网站的费用外包网
  • layui响应式网站开发教程长沙百度首页优化排名
  • 图片点开是网站怎么做谷歌三件套一键安装
  • 外贸管理系统源码温州seo按天扣费
  • wordpress自定义排版网站seo推广哪家值得信赖
  • 关于我们做网站链接制作
  • 驻马店公司做网站免费的黄冈网站有哪些平台
  • 如何利用dw建设网站微信推广朋友圈广告
  • 昆山靠谱的网站建设公司网络推广站
  • 做网站标题头像软文营销写作技巧有哪些?
  • 方圆网通网站建设热搜榜百度
  • 手表哪个网站最好东莞seo顾问
  • 农特产品如何做网站河南新闻头条最新消息
  • 免费网站图片素材网络营销策划方案书范文
  • 网站建设功能定位怎么写培训体系