常見的實現方法是使用兩個數組, t[n-1]和e[n],數組e存放所有的參加排序的元素,在完全二叉樹中是葉子結點,t[]存放 的是比賽的階段性勝者的編號,再進行n趟比賽排序結束,時間復雜度是O(n*log2(n)), 其實我覺得也可以只通過一個數組A[2*n-1]也可以實現,只是標號的換算有點復雜而已.
上傳時間: 2017-05-02
上傳用戶:dragonhaixm
最小生成樹 MST的四種算法實現。 包括普通的Kruskal算法和Prim算法,用Disjoint-Set優化的Kruskal算法和用Heap優化的堆算法。 復雜度分別為O(mn), O(n^2), O(m log n), O(m log n)
上傳時間: 2013-12-10
上傳用戶:stewart·
哲學家吃飯問題 當五個人都拿到左手邊筷子,都等待拿右手邊筷子,則因為誰都不能放下手中的筷子,這樣就進入無止境的等待,構成死鎖 * 解決方法1:奇數號先拿左邊的筷子,偶數號先拿右邊的筷子,即相鄰兩個人先拿其中間夾的筷子,使這個筷子成為臨界資源; * 解決方法2:兩邊的筷子都空閑時,再拿筷子,if(chopstick.flag(n)==false&&chopstick.flag(n 5)==false); * 解決方法3:只允許(n-1)個人同時進餐; * 本程序采用方法1 解決
標簽: 家
上傳時間: 2017-05-27
上傳用戶:zsjzc
一維多項式多組求值,利用系數預處理法對多項式p(x)=an-1x^n-1+an-2x^n-2+...+a1x+a0,進行多組求值。其中n=2^k
標簽: 多項式
上傳時間: 2017-05-29
上傳用戶:戀天使569
The code performs a number (ITERS) of iterations of the Bailey s 6-step FFT algorithm (following the ideas in the CMU Task parallel suite). 1.- Generates an input signal vector (dgen) with size n=n1xn2 stored in row major order In this code the size of the input signal is NN=NxN (n=NN, n1=n2=N) 2.- Transpose (tpose) A to have it stored in column major order 3.- Perform independent FFTs on the rows (cffts) 4.- Scale each element of the resulting array by a factor of w[n]**(p*q) 5.- Transpose (tpose) to prepair it for the next step 6.- Perform independent FFTs on the rows (cffts) 7.- Transpose the resulting matrix The code requires nested Parallelism.
標簽: iterations performs Bailey number
上傳時間: 2014-01-05
上傳用戶:libenshu01
Kullanı lan bazı matlab bilgileri Matlabda kodlar mfile lara yazı lı p kaydedilebilir. Ü st menüden, file, new, mfile. Command windowa yazdı kları nı zı kaydedemezsiniz. Yazdı ğ ı nı z kodu ç alı ş tı rabilmeniz iç in ç alı ş tı ğ ı nı z current directory nin altı na kaydetmelisiniz. Current directory i dosyanı n bulunduğ u yere de gö türebilirsiniz
標簽: 305 bilgileri kaydedile Matlabda
上傳時間: 2014-01-06
上傳用戶:miaochun888
OFDM程序,這么安排矩陣的目的是為了構造共軛對稱矩陣 共軛對稱矩陣的特點是 在ifft/fft的矢量上 N點的矢量 在0,N/2點必須是實數 一般選為0 1至N/2點 與 (N/2)+1至N-1點關于N/2共軛對稱
上傳時間: 2014-02-05
上傳用戶:woshiayin
任務:一堆猴子都有編號,編號是1,2,3 ...m ,這群猴子(m個)按照1-m的順序圍坐一圈,從第1開始數,每數到第N個,該猴子就要離開此圈,這樣依次下來,直到圈中只剩下最后一只猴子,則該猴子為大王。 功能:輸入數據:輸入m,n(m,n 為整數且n<m) 輸出形式:中文提示按照m個猴子,數n 個數的方法,輸出為大王的猴子是幾號 ,建立一個函數來實現此功能
標簽:
上傳時間: 2014-01-25
上傳用戶:athjac
#include <iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n; cin>>n; if(n%2==1) cout<<(n*n-1)/4<<endl; else if (n%4==0) cout <<(n*n)/4-1<<endl; else{ if(n==2) cout<<1<<endl; else{ long long k=n/2-1; cout <<k*k+2*k-3<<endl; } } } return 0; }
標簽: 天津大學acm4022 代碼
上傳時間: 2015-04-20
上傳用戶:nr607
#include <iostream> using namespace std; class Student { public: Student(int, int); int num; int grade; }; Student::Student(int n, int g) { num = n; grade = g; } int maxGradeIndex(Student* s) { int maxGrade, index = 0, i = 0; maxGrade = s[0].grade; for (i = 0; i<5; i++) { if (s[i].grade > maxGrade) { maxGrade = s[i].grade; index = i; } } return index; } int main() { Student a[5] = { Student(1, 86), Student(2, 60), Student(3, 72), Student(4, 95), Student(5, 66) }; int maxGradeStNum = maxGradeIndex(a); cout << "成績最好學生的學號是:" << a[maxGradeStNum].num << endl; cout << "成績最好學生的成績是:" << a[maxGradeStNum].grade << endl; getchar(); return 0; }
上傳時間: 2016-04-23
上傳用戶:burt1025