当前位置:首页 » 操作系统 » 设计算法

设计算法

发布时间: 2022-01-09 02:49:10

① 设计一个算法程序

试题答案:(1)算法步骤:
第一步:使i=1;
第二步:使S=0;
第三步:使S=S+2i;
第四步:使i+1;
第五步:如果i>10,则输出S,结束算法;否则,返回第三步,继续执行算法.
(2)算法的程序框图:

② 如何才能设计出优秀的算法

数据结构中评价一个好的算法,应该从四个方面来考虑,分别是:

一、算法的正确性。

二、算法的易读性。

三、是算法的健壮性。

四、是算法的时空效率(运行)。

算法的设计取决于数据(逻辑)结构,算法的实现取决于所采用的存储结构。数据的存储结构本质上是其逻辑结构在计算机存储器中的实现。为了充分反映数据的逻辑结构,它在内存中的映像包括两个方面,即数据元素之间的信息和数据元素之间的关系。

不同的数据结构有相应的操作。数据操作是定义在数据逻辑结构上的操作算法,如检索、插入、删除、更新和排序。

(2)设计算法扩展阅读

该算法的一般性质包括:

1、对于任何符合输入类型的输入数据,都可以根据算法来解决问题,软件包保证了计算结构的正确性。

2、算法中的每一条指令都必须能够被人或机器执行。

3、确定性算法应该在每一步之后都有明确的下一步指示。也就是说,确保每个步骤都有下一步行动的指示,并且不缺乏或只有模糊的下一步行动指示。

4、有限算法的执行必须以有限的步数结束。

③ 求设计一个算法

因为我是学计算机软件专业的。故我可以很负责任的告诉你:你的这个要求是没有人能够满足的。理由如下:
(1)、首先链表在计算机软件专业的《数据结构》课程中,应该算是最、最复杂的一种数据结构了,它比对数组、堆栈、队列等的操作要来得复杂得多。原因就是在涉及到对各种链表(单链表、双链表等)的编程中,都必须要定义一个(或者多个)指针变量,用来表示单链表(或者是双链表)。而指针又是 C 语言中功能最为强大、但是同时也是概念最难于理解、而且对于 C 语言中的指针部分的代码又是最难于调试的;
(2)、除了上述的(1)之外,你的要求中又涉及到了《数据结构》课程中的排序算法、以及对链表的各种操作(首先要查找到所需要删除的节点、然后再从单链表中进行删除。而且了,删除了节点之后,对原来的单链表还需要重新进行排序)
(3)、编写、并且调试通过一个 C 语言源代码并非一件易事,编写任何一个程序,都必须要在一个集成的编程调试环境中,通过对各个变量设置断点、对整个程序进行单步跟踪,才能够最终调试通过该程序。
故你的要求是不可能通过别人的编程来实现的,而必须依靠自己的艰苦努力去调试通过程序。
以上就是我多年编程的亲身体会。

④ 设计一个算法

写了一段fortran代码,算法详见注释(绿色文字)。

附:模拟运行的结果和代码

⑤ 设计算法,并用c语言实现。

#include<stdio.h>

intchange(intamount,intindex,intconstcoins[]){
if(amount==0)return1;
if(index<=0)return0;
for(inti=amount/coins[index-1];i>=0;--i){
if(change(amount-i*coins[index-1],index-1,coins)){
if(i)
printf("%d*%d",i,coins[index-1]);
return1;
}
}
return0;
}

intmain()
{
intcoins[]={20,50};
intconstsize=sizeof(coins)/sizeof(int);
intamount;
for(inti=0;i<size;++i){
for(intj=i+1;j<size;++j){
if(coins[i]>coins[j]){
inttemporary=coins[i];
coins[i]=coins[j];
coins[j]=temporary;
}
}
}
if(coins[0]<=0){
printf("数据有误,零钱必须大于0 ");
return-1;
}
printf("请输入要兑换的货币金额:");
scanf("%d",&amount);
if(change(amount,size,coins))
printf(" 兑换成功 ");
elseprintf(" 兑换失败 ");
return0;
}

⑥ 如何设计该算法。

算法设计更难,编码只是根据算法的伪代码去实现算法。需要一些写代码的功底。
算法设计更注重的是想法。基本上算法设计出来了,写程序就不难了。
算法设计的工资比编码的工资高得多,一个高中生就能编码了。
在印度,程序员基本上是高中生。而中国的计算机本科生出来基本上做了程序员

⑦ 设计一个算法

根据勾股定理求出第三遍为根号(a²+b²)

所以周长是
a+b+根号(a²+b²)

⑧ 如何设计算法

设计一个正确的算法是一件困难的工作,因为它需要创新,从以太真空中发掘出一个解方案来解决问题。算法设计比对现有的方案进行改良要难得多,因为算法设计的可选择空间太,过多的自由反而成了一种约束。 This book is designed to make you a better algorithm designer. The techniques presented in Part I of this book provide the basic ideas underlying all combinatorial algorithms. The problem catalog of Part II will help you with modeling your application and point you in the right direction of an algorithm or implementation. However, being a successful algorithm designer requires more than book knowledge; it requires a certain attitude, the right problem-solving approach. It is difficult to teach this mindset in a book; yet getting it is essential to become a successful designer. 本书的设计目标是让你成为一个更好的算法设计者。本书第一部分展示有关组合算法的基本原理和基本思想;第二部分的问题清单帮助你为你的问题建模,并且为你指明实现正确算法的方向。尽管如此,要成为一个成功的算法设计者光有书本知识是不够的,面对问题的态度(attitude)和选择正确的方法更重要。书本容易传授知识,很难传授人的心态(mindset)和思考方式;而这种心态和思考却是成为成功的算法设计者的根本条件。 The key to algorithm design (or any other problem-solving task) is to proceed by asking yourself a sequence of questions to guide your thought process. What if we do this? What if we do that? Should you get stuck on the problem, the best thing to do is move onto the next question. In any group brainstorming session, the most useful person in the room is the one who keeps asking, ``Why can't we do it this way?'' not the person who later tells them why. Because eventually she will stumble on an approach that can't be shot down. 算法设计(或其它问题解决任务)的关键是一系列持续的自我反问,这些反问引导我们思维的前进。“如果这样做会怎样?”,“如果那样做又会怎样?”……如果 你被一个问题掐住了,最好的办法就是先搁一下,换一个问题换一个前进的方向试试。在每组头脑风暴会议中,最有价值的人是不断提出为什么的人,不是尔后解说为什么的人。因为我们常常被一些习以为常的东西所拌倒,掉进自己设置的陷阱。 kemin:如果问题解决是一种思考过程,那么思考的形式(过程的严谨性、细致性和正确性)很重要,而思考的内容也不容忽视。因为引导我们思考前进的方式 除反问本身外,反问的内容也很重。就比如参加头脑风暴的材料一样。人大脑的思维功能是硬编码的,人与人之间没有思维规律——质的区别,只是思维的清晰度和 灵敏度——量的差别。人与人之间智力的差别更多体现在思维内容的量上,体现在对外部世界的事实掌握的广度和深度上。 Towards this end, we provide below a sequence of questions to guide your search for the right algorithm for your problem. To use it effectively, you must not only ask the questions, but answer them. The key is working through the answers carefully, by writing them down in a log. The correct answer to, ``Can I do it this way?'' is never ``no,'' but ``no, because ....'' By clearly articulating(明确有力地表达) your reasoning as to why something doesn't work, you can check if it really holds up or whether you have just glossed(掩盖) over a possibility that you didn't want to think hard enough about. You will be surprised how often the reason you can't find a convincing(使人信服的) explanation for something is because your conclusion is wrong. 在末尾我们提供一个反问问题的列表,你不但要反问自己这些问题,更重要是仔细回答这些问题,最好把答案写下来。回答诸如问题“我可以使用这种方式吗?”的 不是一个“不能”就完了,而是“不能,因为……”。通过仔细明确的回答“为什么不能”时,你会发现到底是“真的不能“,还是只是你自己不愿意去深入思考掩 盖了”能“。如果你不曾训练出严谨的思考方式,当你这样做时你会惊讶的发现,为了说明某些东西但却找不到一个令人信服的解释的原因常常是因为你的结论本身 是错的。 An important distinction to keep aware of ring any design process is the difference between strategy and tactics(战略). Strategy represents the quest for the big picture, the framework around which we construct our path to the goal. Tactics are used to win the minor battles we must fight along the way. In problem solving, it is important to check repeatedly whether you are thinking on the right level. If you do not have a global strategy of how you are going to attack your problem, it is pointless to worry about the tactics. 在设计过程中特别重要区分策略和战略的概念。策略是对全局的一个探索,一个构筑通向目标路径的指导框架。战略则是用来解决通向大目标过程的较小的问题。如果你对关于如何对付所面临的问题没有一个全局的策略,那关心战略是不得要领的,予事无补的。在解题领域,不断修正思维的层次(thinking on the right level)是很重要战略。(--莱布尼兹曾经将人的解题思考过程比喻成晃筛子,把脑袋里面的东西都给抖落出来,然后正在搜索的注意力会抓住一切细微的、与问题有关的东西。事实上,要做到能够令注意力抓住这些有关的东西,就必须时刻将问题放在注意力层面,否则即使关键的东西抖落出来了也可能没注意到。) An example of a strategic question is, ``How best can I model my application as a graph algorithm problem?'' A tactical question might be, ``Should I use an adjacency邻接 list or adjacency matrix data structure to represent my graph?'' Of course, such tactical decisions are critical to the ultimate quality of the solution, but they can be properly evaluated only in light of a successful strategy. 一个策略问题的例子是:“我如何才能更好地把我的问题建模成图问题?”。而一个战略问题可能是这样:“我是用邻接列表还是邻接矩阵来实现我的图结构?”。当然,这种战略选择是对解决方案的最终质量起着重要作用;不过战略价值的体现还是基于正确的策略的选择。 When faced with a design problem, too many people freeze up in their thinking. After reading or hearing the problem, they sit down and realize that they don't know what to do next. They stare(凝视) into space, then panic(惊惶), and finally end up settling(沉淀; 决定) for the first thing that comes to mind. Avoid this fate(天数; 运气; 命运 ). Follow the sequence of questions provided below and in most of the catalog problem sections. We'll tell you what to do next! 初学者在面对问题时常常表现出思维凝滞、手足无措和盲目解题。参考以下的反问问题列表和本书的问题清单,我们告诉你应该怎么做。 Obviously, the more experience you have with algorithm design techniques such as dynamic programming, graph algorithms, intractability, and data structures, the more successful you will be at working through the list of questions. Part I of this book has been designed to strengthen this technical background. However, it pays to work through these questions regardless of how strong your technical skills are. The earliest and most important questions on the list focus on obtaining a detailed understanding of the problem and do not require specific expertise. 当然本反问问题列表对读者有背景要求,要求读者对算法设计技术(动态规划、图算法、难解性和数据结构)的熟悉程度。本书第一部分的目标就是对这些技术背景进行强化。不过,不管你的技术背景怎样,通读这些问题对你解题还是很有裨益的。

⑨ 设计算法

很容易
list为新的队列。add(k)方法表示k入队
tree(i)为树i的指针

下面是伪代码。意思一下,能看明白意思跟据你的语言写就好。(DFS)
Void Solve(i)
If Tree(i)=Null then
List.Add(i)
Exit
End
Solve(Tree(i).LC)
Solve(Tree(i).RC)
End Solve

热点内容
上传文件文件夹找不到 发布:2024-09-20 00:26:32 浏览:914
承台箍筋加密区 发布:2024-09-20 00:26:31 浏览:227
笔记本什么配置能流畅运行cf 发布:2024-09-20 00:14:19 浏览:951
实测华为编译器 发布:2024-09-19 23:50:52 浏览:821
linux汇总 发布:2024-09-19 23:46:39 浏览:452
阿里云服务器环境搭建教程 发布:2024-09-19 23:21:58 浏览:837
黄色文件夹图标 发布:2024-09-19 23:19:22 浏览:684
mysql数据库导出导入 发布:2024-09-19 23:00:47 浏览:183
lua脚本精灵 发布:2024-09-19 23:00:41 浏览:659
任务栏文件夹图标 发布:2024-09-19 22:54:25 浏览:101