Ex3-23 親兄弟問題 « 問題描述: 給定n 個整數0 1 1 , , , n- a a a 組成的序列。序列中元素i a 的親兄弟元素k a 定義為: min{ | } k i j n j j i a = a a ³ a < < 。 親兄弟問題要求給定序列中每個元素的親兄弟元素的位置。元素i a 的親兄弟元素為k a 時,稱k 為元素i a 的親兄弟元素的位置。當元素i a 沒有親兄弟元素時,約定其親兄弟元素 的位置為-1。 例如,當n=10,整數序列為6,1,4,3,6,2,4,7,3,5 時,相應的親兄弟元素位 置序列為:4,2,4,4,7,6,7,-1,9,-1。 « 編程任務: 對于給定的n個整數0 1 1 , , , n- a a a 組成的序列,試用抽象數據類型棧,設計一個O(n) 時間算法,計算相應的親兄弟元素位置序列。 « 數據輸入: 由文件input.txt提供輸入數據。文件的第1 行有1 個正整數n,表示給定給n個整數。 第2 行是0 1 1 , , , n- a a a 。 « 結果輸出: 程序運行結束時,將計算出的與給定序列相應的親兄弟元素位置序列輸出到output.txt 中。 輸入文件示例 輸出文件示例 input.txt 10 4 2 4 4 7 6 7 -1 9 -1 output.txt 6 1 4 3 6 2 4 7 3 5
上傳時間: 2013-12-17
上傳用戶:shizhanincc
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
上傳時間: 2013-12-25
上傳用戶:yyyyyyyyyy
算法實現題1-5 最大間隙問題 « 問題描述: 最大間隙問題:給定n 個實數x , , xn 1 2 ,求這n 個數在實軸上相鄰2 個數之間的最 大差值。假設對任何實數的下取整函數耗時O(1),設計解最大間隙問題的線性時間算法。 « 編程任務: 對于給定的n 個實數n x , x , , x 1 2 ,編程計算它們的最大間隙。 « 數據輸入: 輸入數據由文件名為input.txt的文本文件提供。文件的第1 行有1 個正整數n。接下來 的1 行中有n個實數n x , x , , x 1 2 。 « 結果輸出: 程序運行結束時,將找到的最大間隙輸出到文件output.txt中。 輸入文件示例 輸出文件示例 input.txt 5 2.3 3.1 7.5 1.5 6.3 output.txt 3.2
上傳時間: 2016-05-28
上傳用戶:咔樂塢
Ex4-22 單射函數問題 « 問題描述: 設函數f將點集S = {0,1, , n -1}映射為f (S) = { f (i) | iÎ S} Í S 。單射函數問題要 從S中選取最大子集X Í S 使f (X )是單射函數。 例如,當n=7, f (S) = {1,0,0,2,2,3,6} Í S 時, X = {0,1,6} Í S 是所求的最大子集。 « 編程任務: 對于給定的點集S = {0,1, , n -1}上函數f,試用抽象數據類型隊列,設計一個O(n)時 間算法,計算f的最大單射子集。 « 數據輸入: 由文件input.txt 提供輸入數據。文件的第1 行有1 個正整數n,表示給定的點集 S = {0,1, , n -1}。第2 行是f (i)的值,0 £ i < n。 « 結果輸出: 程序運行結束時,將計算出的f的最大單射子集的大小輸出到output.txt中。 輸入文件示例 輸出文件示例 input.txt 7 1 0 0 2 2 3 6 output.txt 3
上傳時間: 2016-05-28
上傳用戶:tyler
不用說的好,我們室主任開發的Photonics cyrestal band gap計算Fortran代碼。注意不要忘了input文本。
標簽:
上傳時間: 2014-01-23
上傳用戶:jcljkh
Tasks Read the textbook about the details of Vigenére Cipher. Implement the algorithm by C or C++. Requirements You do this lab in a group of two students. Your program should have input and output as follows: csci>a.out --> Please input the key: receptive --> Please input the plain text: wearediscoveredsaveyourself --> The cipher text is : nicvtwqngfzgvtwavzvcqyglmgj -->The original message is: wearediscoveredsaveyourself • You should test your program with several runs.
標簽: the Implement algorithm textbook
上傳時間: 2013-12-21
上傳用戶:bruce5996
% DYNMODES calculates ocean dynamic vertical modes % taking a column vector of Brunt-Vaisala values (Nsq) at % different pressures (p) and calculating some number of % dynamic modes (nmodes). % Note: The input pressures need not be uniformly spaced, % and the deepest pressure is assumed to be the bottom.
標簽: Brunt-Vaisala calculates DYNMODES vertical
上傳時間: 2013-12-06
上傳用戶:busterman
This guide reviews the rules and syntax of the principle commands that comprise C and its object-oriented cousin, C++. The reference consists of 19 chapters that define operators and the standard input/output, string, character, and more.
標簽: object-ori and principle the
上傳時間: 2014-01-15
上傳用戶:ve3344
The CoinUtils project is a collection of open-source utilities developed and used by a variety of other projects in the COIN-OR repository. The project includes classes for storing and manipulating sparse matrices and vectors, performing matrix factorization, parsing input files in standard formats, building representations of mathematical programs, comparing floating point numbers with a tolerance, performing simple presolve operations, and warm starting algorithms for mathematical programs, among others.
標簽: open-source collection CoinUtils developed
上傳時間: 2013-12-19
上傳用戶:xmsmh
Description 為了宣傳本次“網宿科技杯”廈門大學第五屆程序設計競賽,系里面做了兩張精美的海報。經過了精確的計算,為了達到最佳美觀效果,每張海報都有自己最佳的粘貼位置。但是現在問題是,如果兩張海報都要求貼在最佳位置時,很有可能有部分地方會重疊在一起。現在您來判斷一下這兩張海報是否重疊。 Input 輸入包含兩行,每一行有四個整數來描述這個海報的最佳粘貼位置,X,Y,W,H(-10000<= X,Y <= 10000)(0 < W, H <= 10000),X,Y表示海報左下角的坐標,W,H分別表示寬度和高度。 Output 輸出"Yes"表示兩張海報互相重疊(表示存在一個面積大于0的公共區域),否則輸出"No"。(不包含引號,注意大小寫) Sample Input -10 -10 20 30 0 0 30 20 Sample Output Yes
標簽: Description 大學 程序設計 競賽
上傳時間: 2016-06-26
上傳用戶:gxf2016