求一个easy算法,简单调整位置

guogangj 2010-11-24 02:29:49
class CItem
{
BYTE blah[HUGE];
};

CItem data[5];

INT reposition[5] = {4,2,0,3,1};

要求,根据repositon的内容调整dt的内容,如上,把原来下标4的元素调到0,把原来下标2的元素调到1。

写个算法,复杂度为O(n),还要尽量节省空间,因为HUGE可以很大,并且data可能远远不止5个元素。
...全文
145 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
guogangj 2010-11-27
  • 打赏
  • 举报
回复
我总结了一下,代码贴这里:
http://www.cppblog.com/guogangj/archive/2010/11/27/134843.html
guogangj 2010-11-25
  • 打赏
  • 举报
回复
to asmlearn

你是说递归吗?最好能贴一下代码,不过递归可是需要在程序栈区中复制代码的,递归了太多层的话会导致栈溢出,这也不是一种节省空间的做法。
guogangj 2010-11-25
  • 打赏
  • 举报
回复
呵呵,假如就有这么一道题目,需要节省内存,该怎么做?
一个嵌入式的环境,往往真的不能动态分配出一大块的内存来哦。
donkey301 2010-11-25
  • 打赏
  • 举报
回复
保证下一次的Distination是上一次的Source,这样只要一个临时变量就行了
譬如:
CItem Temp;
Source Distination
0 --> Temp
4 --> 0
1 --> 4
2 --> 1
Temp --> 2

3 --> Temp
...
Temp --> ..
pmars 2010-11-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 pmars 的回复:]
开大数组不行么?
CItem array[MAX] ;
for : array[i] = data[reposition[i]] ; //数据类型好像不协调哈!
for : data[i] = array[i] ;
[/Quote]
呵呵,array为CItem类型的啊!
pmars 2010-11-24
  • 打赏
  • 举报
回复
[Quote=引用楼主 guogangj 的回复:]
class CItem
{
BYTE blah[HUGE];
};

CItem data[5];

INT reposition[5] = {4,2,0,3,1};

要求,根据repositon的内容调整dt的内容,如上,把原来下标4的元素调到0,把原来下标2的元素调到1。

写个算法,复杂度为O(n),还要尽量节省空间,因为HUGE可以很大,并且data可能远远不止5个……
[/Quote]
开大数组不行么?
int array[MAX] ;
for : array[i] = data[reposition[i]] ; //数据类型好像不协调哈!
for : data[i] = array[i] ;
donkey301 2010-11-24
  • 打赏
  • 举报
回复
为什么不用指针呢?这样只要交换指针地址就行了,没必要交换内容的。
asmlearn 2010-11-24
  • 打赏
  • 举报
回复
1、写一个交换函数,入口参数为要交换的两个下标索引。
2、依次处理数组每个元素,将当前索引和元素值作为参数传给上一个交换函数。
至于节省空间可能要用到动态分配,不过现在内存芯片动不动就上G,开个大数组也没关系吧。
粒子群优化算法是一种新颖的仿生、群智能优化算法。该算法原理简单、需调整的参数少、收敛速度快而且易于实现,因此近年来粒子群算法引起了广大学者的关注。然而到目前为止粒子群算法的在理论分析和实践应用方面尚未成熟,仍有大量的问题需进一步研究。本文针对粒子群算法易出现“早熟”陷入局部极小值问题对标准粒子群算法进行改进并将改进的粒子群算法应用于BP神经网络中。本文的主要工作如下:本文首先介绍了粒子群算法的国内外的研究现状与发展概况,较系统地分析了粒子群优化算法的基本理论,总结常见的改进的粒子群优化算法。其次介绍了Hooke-Jeeves模式搜索法的算法分析、基本流程及应用领域。针对标准粒子群优化算法存在“早熟”问题,易陷入局部极小值的缺点,本文对标准粒子群算法进行改进。首先将原始定义的初始种群划分为两个相同的子种群,采用基于适应度支配的思想分别将每个子种群划分为两个子集,Pareto子集和N_Pareto子集;然后将两个子群中的适应度较优的两个Pareto子集合为新种群。Griewank和Rastrigin由于新种群的参数设置区别于标准粒子群算法的参数设置,新的粒子与标准种群中的粒子飞行轨迹不同,种群的探索范围扩大,从而使算法的全局搜索能力有所提高。 为平衡粒子群算法的全局寻优能力和局部寻优能力,提高粒子群算法解精度和效率,本文在新种群寻优过程中引入具有强收敛能力Hooke-Jeeves搜索法,提出了IMPSO算法。雅文网www.lunwendingzhi.com,并用IMPSO算法对标准基准测试函数进行实验,将得到的实验结果并与标准粒子群算法对基准函数的实验结果进行对比,仿真结果证明了该改进的粒子群算法的有效性。 最后本文研究改进的粒子群算法在BP神经网络中的应用。首先介绍人工神经网络的原理及基于BP算法的多层前馈神经网络,其次用IMPSO算法训练BP神经网络并给出训练流程图。 将IMPSO算法训练的BP神经网络分别应用于齿轮热处理中硬化层深的预测以及用于柴油机的缸盖与缸壁的故障诊断中,并将预测结果、诊断结果与BP神经网络、标准粒子群优化算法训练的BP神经网络的实验结果进行对比,实验结果证明了改进的粒子群算法训练BP网络具有更强的优化性能和学习能力。 英文简介: Particle swarm optimization algorithm is a novel bionic, swarm intelligence optimization algorithm. The algorithm principle is simple, less need to adjust the parameters and convergence speed is fast and easy to implement, so in recent years, particle swarm optimization (pso) to cause the attention of many scholars. So far, however, the particle swarm algorithm are not mature in theory analysis and practice applications, there are still a lot of problems need further research. Based on particle swarm algorithm is prone to "premature" into a local minimum value problem to improve the standard particle swarm algorithm and improved particle swarm optimization (pso) algorithm was applied to BP neural network. This paper's main work is as follows: at first, this paper introduces the particle swarm algorithm in the general situation of the research status and development at home and abroad, systematically analyzes the basic theory of particle swarm optimization algorithm, summarizes the common improved particle swarm optimization algorithm. Secondly introduces the analysis method of Hooke - Jeeves pattern search algorithm, the basic process and application fields. In view of the standard particle swarm optimization algorithm "precocious" problems, easy to fall into local minimum value, in this paper, the standard particle swarm algorithm was improved. First of all, the original definition of the initial population is divided into two identical sub populations, based on the fitness of thought respectively each child population is divided into two subsets, and Pareto subset N_Pareto subset; And then has a better fitness of two subgroups of two Pareto set for the new population. Griewank and Rastrigin because of the new population parameter setting differs from the standard particle swarm algorithm of the parameter is set, the new particles and particle trajectories in the different standard population, population expanding, which makes the algorithm's global search ability have improved. To balance the global search capability of the particle swarm algorithm and local optimization ability, and improve the precision and efficiency of particle swarm optimization (pso) algorithm, introduced in this article in the new population optimization process has a strong convergence ability to search method of Hooke - Jeeves, IMPSO algorithm is proposed. And standard benchmark test functions with IMPSO algorithm experiment, will receive the results with the standard particle swarm algorithm, comparing the experimental results of benchmark functions, the simulation results prove the validity of the improved particle swarm algorithm. At the end of the paper research the improved particle swarm algorithm in the application of the BP neural network. First this paper introduces the principle of artificial neural network and based on the multi-layer feed-forward neural network BP algorithm, secondly by IMPSO algorithm training the BP neural network and training flow chart is given. IMPSO algorithm training the BP neural network respectively used in the gear heat treatment hardening layer depth prediction and used for fault diagnosis of diesel engine cylinder head and cylinder wall, and the predicted results, the diagnostic results, the standard particle swarm optimization algorithm with BP neural network of training BP neural network, comparing the experimental results of the experimental results show that the improved particle swarm optimization (pso) training BP network has better optimization performance and learning ability.
SoftOrbits Easy Photo Unblur 2.0 绿色便携版及序列号 SoftOrbits Easy Photo Unblur 是一款专业的图像处理软件由易破解YIPOJIE.CN!精选收集互联网资源并整理相关Patch Crack KeyGen独家发布,软件的主要功能修复照片抖动导致模糊的照片,软件的功能特色非常的丰富和实在,可以一键进行修复,支持批量。在修复的过程中可以对照片进行编辑处理,完成之后照片的质量会更加的高,处理过程非常的简单Easy Photo Unblur绿色版是款照片模糊修复软件,智能算法分析检测图像上的散焦对象或运动模糊图案,不会锐化图片,而是通过智能修复来恢复图片,锐化错误聚焦的图像,修复相机抖动和运动模糊。人工智能算法分析你的图像,以检测焦点不集中的物体或运动模糊模式,应用智能修复而不是过度锐化整个图像。 只需点击一下即可修复焦点错误你将它计时并抓住了那个独特的时刻……后来才发现镜头错误。没有什么比抛弃一张独特的照片更痛苦,因为有轻微的焦点错误。错过了机会?如果您使用Easy Photo Unblur,请勿使用!错过了焦点?Easy Photo Unblur将为您修复它!该工具可以通过对这些模糊对象应用智能重新聚焦算法来纠正中小焦点错误。最终的结果?一张图片胜过千言万语! 相机抖动占绝大多数被宠坏的照片。光学和电子图像稳定和超高ISO可以提供帮助,但那些通常具有很高的价格标签。即使是配备OIS的凸轮有时也会产生模糊的画面。幸运的是,这种模糊是最容易修复的。Easy Photo Unblur应用人工智能检测抖动模式,仔细重新对齐图像以获得完美清晰的外观。 Easy Photo Unblur使用与许多其他工具不同的握手减少技术。该工具不是简单地将Unsharp Mask过滤器放在图像上,而是应用智能技术来检测握手模糊的模式,并应用其魔力来修复特定模式。 减少运动模糊有两种类型的运动模糊,您可能只想修复一个。拍摄长时间曝光的移动物体时,物体可能会在照片上显得模糊。这是因为当快门打开时物体已经移动。Easy Photo Unblur只需点击几下即可为您解决此类问题。 第二种运动模糊怎么样?通过在拍摄时使用相机跟踪物体的移动,您仍然可以拍摄长时间曝光的移动物体的精彩照片。如果你这样做,你会有一个尖锐的主题和模糊的背景,这是一个完美的表示静止图片中的运动。您不想修复此类模糊。 主要功能 修复失焦的镜头 纠正运动模糊 修复由于相机抖动而模糊的照片 提供微缩和光圈模糊效果 批量模式有助于一次性修复一堆图像 内置照片调整,亮度,对比度,色温和伽玛控制 裁剪工具,旋转和调整图片大小
粒子群算法,也称粒子群优化算法(Particle Swarm Optimization),缩写为 PSO, 是近年来发展起来的一种新的进化算法(Evolutionary Algorithm - EA)。PSO 算法属于进化算法的一种,和模拟退火算法相似,它也是从随机解出发,通过迭代寻找最优解,它也是通过适应度来评价解的品质,但它比遗传算法规则更为简单,它没有遗传算法的“交叉”(Crossover) 和“变异”(Mutation) 操作,它通过追随当前搜索到的最优值来寻找全局最优。这种算法以其实现容易、精度高、收敛快等优点引起了学术界的重视,并且在解决实际问题中展示了其优越性。粒子群算法是一种并行算法。 BP(Back Propagation)神经网络是1986年由Rumelhart和McCelland为首的科学家小组提出,是一种按误差逆传播算法训练的多层前馈网络,是目前应用最广泛的神经网络模型之一。BP网络能学习和存贮大量的输入-输出模式映射关系,而无需事前揭示描述这种映射关系的数学方程。它的学习规则是使用最速下降法,通过反向传播来不断调整网络的权值和阈值,使网络的误差平方和最小。BP神经网络模型拓扑结构包括输入层(input)、隐层(hidden layer)和输出层(output layer)。(Particle swarm optimization, also known as particle swarm optimization (Particle Swarm Optimization), abbreviated as PSO, is a new evolutionary algorithm developed in recent years (Evolutionary Algorithm- EA). Kind, and simulated annealing algorithm PSO algorithm is similar evolutionary algorithms, it is also starting a random solution, through an iterative search for the optimal solution, which is also used to uate the quality through fitness solution, but it is simpler than genetic algorithm rules It has no genetic algorithm " crossover" (Crossover) and " variant" (Mutation) operation, which by following the current search to find the optimal value to the global optimum. This algorithm is its easy implementation, high accuracy, fast convergence, etc. attracted academic attention and show its superiority in solving practical problems. PSO algorithm is a parallel algorithm. BP (Back Propagation) neural network is a 1986 team of scientists headed by Rumelhart and McC)

33,006

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧