1. 如何設計該演算法。
演算法設計更難,編碼只是根據演算法的偽代碼去實現演算法。需要一些寫代碼的功底。
演算法設計更注重的是想法。基本上演算法設計出來了,寫程序就不難了。
演算法設計的工資比編碼的工資高得多,一個高中生就能編碼了。
在印度,程序員基本上是高中生。而中國的計算機本科生出來基本上做了程序員
2. 設計演算法通常採用什麼的逐步求精方法
fpga由pal(可編程陣列邏輯)、gal(通用陣列邏輯)發展而來,其基本設計思想是藉助於eda開發工具,用原理圖、狀態機、布爾表達式、硬體描述語言等方法進行系統功能及演算法描述,設計實現並生成編程文件,最後通過編程器或下載電纜用目標器件來實現。
---fpga器件採用邏輯單元陣列(lca,logic cell array)結構、sdram工藝,其中lca由三類可編程單元組成。
3. 關於設計演算法
(2+98)+(6+94)+(8+92)+....+(46+54)+50
還要怎麼簡單啊?
int all=2;
for(int i=0;i<=(98-2)/4;i++)
{
all+=4;
}
4. 設計最優演算法
你們呢
5. 設計演算法
很容易
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
6. 設計一個演算法
根據勾股定理求出第三遍為根號(a²+b²)
所以周長是
a+b+根號(a²+b²)
7. 設計一個演算法:
1)定位到順序表的首結點
2)訪問該結點,若其數據域為x,將其替換為y
3)若該結點是表尾結點,演算法結束。否則指向其下一結點,然後轉2)。
8. 如何設計演算法
設計一個正確的演算法是一件困難的工作,因為它需要創新,從以太真空中發掘出一個解方案來解決問題。演算法設計比對現有的方案進行改良要難得多,因為演算法設計的可選擇空間太,過多的自由反而成了一種約束。 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. 當然本反問問題列表對讀者有背景要求,要求讀者對演算法設計技術(動態規劃、圖演算法、難解性和數據結構)的熟悉程度。本書第一部分的目標就是對這些技術背景進行強化。不過,不管你的技術背景怎樣,通讀這些問題對你解題還是很有裨益的。
9. 設計一個演算法
寫了一段fortran代碼,演算法詳見注釋(綠色文字)。
附:模擬運行的結果和代碼
10. 設計演算法,並用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;
}