CodeBus
www.codebus.net
Search
Sign in
Sign up
Hot Search :
Source
embeded
web
remote control
p2p
game
More...
Location :
Home
Search - n2-1
Main Category
SourceCode
Documents
Books
WEB Code
Develop Tools
Other resource
Search - n2-1 - List
[
Algorithm
]
矩阵的压缩存储(对称矩阵,三角矩阵,稀疏矩阵)
DL : 1
矩阵的压缩存储 问题描述:矩阵是许多科学与工程计算问题中出现的数学对象。在此,我们感兴趣的不是矩阵本身,我们所关心的是研究表示矩阵的方法,以使对矩阵的各种运算能有效地完成。一个矩阵一般由m行和n列元素组成,一般的m*n阶矩阵,可表示成一个m*n的二维数组,例如matrix[m][n],需要的存储空间是m*n 实现要求: 若矩阵中的元素是对称的,即矩阵中第i行第j列与第j行第i列元素的值相等,即matrix[i][j]=matrix[j][i],我们把这种矩阵称为对称矩阵。对于n*n阶对称矩阵,我们可以为每一对对称元素分配一个存储空间,即只需要存储其下三角(包括对角线)或上三角中的元素即可。这样,就可将n2个元素压缩存储到n(n+1)/2个存储单元中。请实现该功能 当一个n*n阶矩阵的主对角线上方或下方的所有元素皆为零时,称该矩阵为三角矩阵。对于三角矩阵,我们同样也可采用对称矩阵的压缩存储方式将其上三角或下三角的元素存储在一维数组中,达到节约存储空间的目的。请实现该功能 除了对称矩阵和三角矩阵等特殊矩阵外,在实际应用中我们还经常遇到这样一类矩阵,存储在矩阵中的大量元素值为零,而且零元素的分布没有规律,这样的矩阵称为稀疏矩阵。对于稀疏矩阵,采用二维数组表示既浪费大量的存储单元来存储零元素,又要花大量的时间进行零元素的运算。为此,我们对稀疏矩阵采取三元组法进行存储。请实现该功能
Date
: 2011-03-21
Size
: 297.05kb
User
:
runonce
[
Algorithm
]
Sink
DL : 0
Ex8-4 汇点问题 « 问题描述: 采用邻接矩阵表示一个具有n 个顶点的图时,大多数关于图的算法时间复杂性为 O(n2 ),但也有例外。例如,即使采用邻接矩阵表示一个有向图G,确定G 是否含有一个 汇(即入度为n-1,出度为0 的顶点),只需要O(n)计算时间。试写出其算法。 « 编程任务: 对于给定的有n个顶点的图G 的邻接矩阵,各顶点依次编号为1,2,…,n。试设计一 个O(n)时间算法,计算图G 的汇点。 « 数据输入: 由文件input.txt提供输入数据。文件的第1 行有1 个正整数n,表示图G 中顶点个数。 第2 行起每行n个数,共n行,给出图G 的邻接矩阵。 « 结果输出: 程序运行结束时,将计算出的汇点编号输出到output.txt中。当图G 没有汇点时输出0。 输入文件示例 输出文件示例 input.txt 5 0 0 1 1 1 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 output.txt 3-err
Date
: 2026-01-09
Size
: 51kb
User
:
Tonsen
[
Algorithm
]
n2
DL : 0
FLAC平台上计算邓肯张模型的实例。五次加载五次卸载
Date
: 2026-01-09
Size
: 1kb
User
:
李讳名
[
Algorithm
]
Mysteryproblem
DL : 0
重排九宫是一个古老的单人智力游戏。据说重排九宫起源于我国古时由三国演义故事“关羽义释曹操”而设计的智力玩具“华容道”,后来流传到欧洲,将人物变成 数字。原始的重排九宫问题是这样的:将数字1~8按照任意次序排在3×3的方格阵列中,留下一个空格。与空格相邻的数字,允许从上,下,左,右方向移动到 空格中。游戏的最终目标是通过合法移动,将数字 1~8 按行排好序。在一般情况下,n2-1 谜问题是将数字 1~n2-1 按照任意次序排在n×n的方格阵列中,留下一个空格。允许与空格相邻的数字从上,下,左,右 4个方向移动到空格中。游戏的最终目标是通过合法移动,将初始状态变换到目标状态。 对于给定的n×n方格阵列中数字1~n2-1 初始排列,编程计算将初始排列通过合法移动变换为目标状态最少移动次数。 ′数据输入: 文件的第1行有1个正整数n。以下的n行是 n×n方格阵列的中数字1~n2-1的初始排列,每行有n个数字表示该行方格中的数字, 0表示空格。 接着n行是n×n方 格阵列的中数字1~n2-1的目标排列,每行有n个数字表示该行方格中的数字, 0表示空格。1<=n<=10 结果输出: 第 1 行是最少移动次数。-Rearrangement Jiu Gong is an ancient single puzzle. Jiu Gong is said to originate from the rearrangement of China in ancient times by the Three Kingdoms story, "Guan Yu Yi Cao release" designed to intellectual toys "Huarong" and later spread to Europe, will figure into a figure. Jiugong original rearrangement problem is this: will the number 1 to 8 in accordance with any order of ranking, the box in the 3 × 3 array, leaving a space. And the number of adjacent spaces, to allow from the top, bottom, left and right direction to move to the space. The ultimate goal of the game through the legal move, the numbers 1 to 8 lined by row sequence. Under normal circumstances, n2-1 mystery issue is the number 1 ~ n2-1 in accordance with any order of rank n × n array of squares, leaving a space. Permitted number of adjacent spaces from the top, bottom, left and right four directions to move to an empty cell. The ultimate goal of the game through the legal move, transform the initial state to target
Date
: 2026-01-09
Size
: 863kb
User
:
wakaka
[
Algorithm
]
PiCalculator
DL : 0
这个算法是平方收敛的(每次迭代有效位数增加一倍), 这样要求到Q位有效数字,就至少要log2Q+1次迭代 显然,这种计算是要高精度表示的, 我所用的算法就是普通的高精度加减乘除 加减是O(n)的,时间花费很少。 乘除是O(n2)的,主要的时间花费都在这上面。 而由这个算法中可以看到,bn的计算需要开根号。 这里有两种开根号的办法: ①用初中教我们的方法,每次开两位根号,用除法减掉, 这样所需时间为n2·n/2=O(n3),不可忍受! ②用牛顿迭代法。 即 x0=任意正数, xn+1=(xn+a/xn)/2 同样,这个算法也是平方收敛的。 其中除法是O(n2)的 故还是需要O(n2log2n)的时间 -Square convergence of the algorithm is (each iteration doubles the effective number of bits), Such a request to the Q digits to at least log2Q 1 iterations Obviously, this calculation is expressed to high accuracy, The algorithm I used is the ordinary high-precision addition, subtraction Addition and subtraction is O (n), the time spent very little. Multiplication and division is O (n2), mainly time spent in this way. By this algorithm can be seen, bn square root calculation needs. There are two ways to open root: ① The middle school to teach our method, each time to open the two radicals, with the division to lose, This time is n2 · n/2 = O (n3), can not stand it! ② The Newton iteration. That x0 = any positive number, xn 1 = (xn a/xn)/2 Similarly, the square is also the convergence of the algorithm. One division is O (n2) of the It still needs O (n2log2n) time
Date
: 2026-01-09
Size
: 44kb
User
:
joyeep
[
Algorithm
]
GetZmnSinaular
DL : 0
这个函数用来计算阻抗阻阵中的奇异项积分,m1,m2,m3 --检验函数三角形三个顶点编号,其中,m1与m边对应 //n1,n2,n3 --展开函数三角形三个顶点编号,其中n1与n边相对-the singular integrals are calculated by analytical method. m1,m2,m3 three point of the triangle
Date
: 2026-01-09
Size
: 1kb
User
:
李华
[
Algorithm
]
Ex4_3
DL : 0
傅里叶变换是一种将信号从时域变换到频域的变换形式,是信号处理的重要分析工具。离散傅里叶变换(DFT)是傅里叶变换在离散系统中的表示形式。但是DFT的计算量非常大, FFT就是DFT的一种快速算法, FFT将DFT的N2 步运算减少至 ( N/2 )log2N步。-Fourier transform is a signal from the time domain to frequency domain transformation form, is an important signal processing analysis tools. Discrete Fourier Transform (DFT) is the Fourier transform in the discrete system representation. However, very large computational DFT, FFT is a fast algorithm for DFT, FFT DFT of the N2-step operation will be reduced to (N/2) log2N step.
Date
: 2026-01-09
Size
: 11kb
User
:
刘璐
[
Algorithm
]
formats
DL : 0
类似于fortran语言的格式控制 用法: s=formats(n1,s1,n2,s2,...) s1,s2为字符型,n1,n2为整型,如果值等于1,可以忽略不写 例如用于控制输出: x=rand(1,5) y=[ hello where which ] z=1:3 sprintf([ x= ,formats(5, 5.2f , \n ), y= ,formats( s , \n ), z= ,formats(3, d )],x,y ,z) formats(5, 5.2f )表示5个 5.2f格式的输出,而不用写5次了,这一点matlab 没有fotran自带的好- quick replicates simple format string and compose a complex format string Usage: s=formats(|[times1],formatstring1,|[times2],[formatstring2],...) s return times1 replicates formatstring1,then times2 replicates formatstring2, ... for example: x=rand(1,5) y=[ hello where which ] z=1:3 sprintf([ x= ,formats(5, 5.2f , \n ), y= ,formats( s , \n ), z= ,formats(3, d )],x,y ,z) See also FORMAT, REPMAT, FPRINTF, SPRINTF
Date
: 2026-01-09
Size
: 1kb
User
:
zhoudg
[
Algorithm
]
8
DL : 0
C++实现古老数学问题。 当a, b为正整数,a<b时求所有N的值使得: a/b=1/N1+1/N2+...+1/Nn-inplement a>0, b>0 a<b, caculate a/b.
Date
: 2026-01-09
Size
: 1kb
User
:
this one
[
Algorithm
]
bouble-tower
DL : 0
背景 从前,有一个古老的帝国有两个形状不同的塔分别在不同的两个城市里。这两个塔是用圆形的砖一块一块建成的。这些圆形砖的高度是一样的,其半径都是整数。很明显,尽管这两个塔形状不同,但造塔所使用的圆形砖却有很多是相同的。 过了很多年,一个国王命令他的建筑师们移除两个塔的部分砖以便使它们的形状完全一样,同时使两个塔的高度尽可能的高,并且新塔的砖瓦的排列顺序必须与原来的一样。国王认为这样的两个塔象征着这两个城市之间的和谐和平等,于是命名它们为双胞胎塔。 任务 现在,两千年以后,你可以来处理这样非常简单的问题:给你两个不同形状塔的描述,你只要算出能建成的新双塔的最多的砖瓦数。 输入 输入包括以下内容:第一行输入两个整数 N1 和 N2 (1 <= N1,N2 <= 100) 分别表示最初时两个塔的砖瓦数;第二行输入 N1 个正整数表示第一个塔砖瓦的半径(按从上到下的顺序排列);下面的一行输入 N2 个整数表示第二个塔砖瓦的半径(按从上到下的顺序排列)。 当输入的 N1 和 N2 为 0 时结束。 输出 输出建成的新双塔的最多的砖瓦数。-Background There was once an ancient empire with two different shapes of the two towers at different cities . The two circular brick tower is built piece by piece . These circular brick height is the same, the radius are integers. Clearly, although both towers of different shapes , but making use of the circular tower there are many tiles are identical . Over many years, a king ordered his architects to remove two brick towers in order to make them part of exactly the same shape , but the height of the two towers as high as possible , and the new order of brick tower must be the same as the original . Kings think this two tower symbolizes the harmony between the two cities and equality , so named them as twin towers. Task Now, two years later, you can come to deal with this very simple question : give you a description of two towers of different shapes , as long as you can calculate the new towers built up brick number. Enter Inputs include the following: The first line of
Date
: 2026-01-09
Size
: 1.43mb
User
:
kenber
[
Algorithm
]
6609_Minimal_-Subarray_-Length.tar
DL : 0
Solution for the problem 6609 - Minimal Subarray Length(ACM-ICPC Live Archive), uses Kadane s Algorithm. Time of complexity O(n2).
Date
: 2026-01-09
Size
: 1kb
User
:
enfranks
[
Algorithm
]
method-of-interpolation
DL : 0
各种插值算法 1 拉格朗日插值(POLINT) 2 有理函数插值(RATINT) 3 三次样条插值(SPLINE(二阶导数值)) 4 有序表的检索法(LOCATE(二分法), HUNT(关联法)) 5 插值多项式(POLCOE(n2), POLCOF(n3)) 6 二元拉格朗日插值(POLIN2) 7 双三次样条插值(SPLIE2)-Various interpolation algorithm 1 Lagrange Interpolation (POLINT) 2 rational function interpolation (RATINT) 3 Cubic Spline Interpolation (SPLINE (second derivative values)) Table 4 ordered retri method (LOCATE (dichotomy), HUNT (correlation method)) 5 interpolation polynomial (POLCOE (n2), POLCOF (n3)) 6 diacids Lagrange Interpolation (POLIN2) Seven pairs of cubic spline interpolation (SPLIE2)
Date
: 2026-01-09
Size
: 5kb
User
:
lin
[
Algorithm
]
line-plane-intersection
DL : 0
求空间直线与平面的交点 已知直线L过点m(m1,m2,m3),且方向向量为VL(v1,v2,v3), 平面P过点n(n1,n2,n3),且法线方向向量为VP(vp1,vp2,vp3),求得直线与平面的交点O的坐标(x,y,z)(Find the intersection of space, line and plane the line L is known to be over M (M1, M2, m3), and the direction vector is VL (V1, V2, V3),The plane P passes over the point n (N1, N2, N3), and the normal direction vector is VP (VP1, VP2, VP3), and the intersection of the line and plane is obtained. The coordinates of O (x, y, z) are obtained.)
Date
: 2026-01-09
Size
: 113kb
User
:
lion_han
CodeBus
is one of the largest source code repositories on the Internet!
Contact us :
1999-2046
CodeBus
All Rights Reserved.