原创 《算法問題實戰策略》6-1計算1到n的之和的遞歸函數和6-2求在n個元素中選擇m個元素的所有可能的組合

//6-1計算1到n的之和的遞歸函數 int recursive_sum(int n){ if(n==1)return 1; return n+recursive_sum(n-1); } //6-2求在n個元素中選

原创 《算法競賽入門經典》6-7 Trees on the level UVA122——二叉樹的層次遍歷(寬度優先遍歷BFS)

Trees on the level       UVA - 122  Trees are fundamental in many branches of computer science (Pun definitely intended

原创 《阿哈!算法》4-1不撞南牆不回頭 4-2 解救小哈——深度優先搜索

深度優先搜索關鍵在於解決“當下該如何做”。至於“下一步如何做”則與當下該如何做“是一樣的。 深度優先搜索模型: void dfs(int step){ 判斷邊界,一般在這裏輸出最終的結果 嘗試每一種可能for(int

原创 Matlab(一)數值數據

1.數值數據類型的分類 (1)整型 無符號8位整數數據範圍:00000000~11111111(0~28-1)。 帶符號8位整數數據範圍:10000000~01111111(-27~27-1)。 (2)浮點型 single函數:將其他類型

原创 《阿哈!算法》4-3 解救小哈——廣度優先搜索

廣度優先搜索:使用隊列實現 廣度優先搜索代碼: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <string.h

原创 《阿哈!算法》2-1解密QQ號——隊列

新學期開始了,小哈是小哼的新同桌(小哈是個小美女哦~),小哼向小哈詢問QQ號,小哈當然不會直接告訴小哼啦,原因嘛你懂的。所以小哈給了小哼一串加密過的數字,同時小哈也告訴了小哼解密規則。規則是這樣的:首先將第1個數刪除,緊接着將第2個數放到

原创 《阿哈!算法》2-5 模擬鏈表——用數組來實現鏈表

鏈表中的每一個結點只有兩個部分。即data和struct node * next; 構成:第一個整型數組data是用來存放序列中具體數字的。另一個整型數組right是用來存放當前序列中每一個元素右邊的元素在數組data中位置的。例如rig

原创 《阿哈!算法》2-2解密迴文——棧

棧的實現之需要一個一維數組和一個指向棧頂的變量top即可。通過top對棧進行插入和刪除操作。 初始化棧只需要top=0; 入棧:top++;s[top]=x;簡寫爲s[++top]=x; 棧可以用來判斷迴文,驗證括號的匹配等 題目代碼如下

原创 《阿哈!算法》2-4鏈表

指針:存儲一個地址,確切地說是存儲一個內存空間的地址。 malloc函數的作用是從內存中申請分配指定字節大小的分配空間。可以用 malloc(sizeof(int));申請。我們用指針來對這空間進行操作。用一個指針指向這個空間,即存儲這個

原创 《阿哈!算法》4-1不撞南牆不回頭——深度優先搜索

深度優先搜索關鍵在於解決“當下該如何做”。至於下一步如何做“則與”當下該如何做“是一樣的。     #include <stdio.h> #include <stdlib.h> #include <math.h> #include <c

原创 《算法競賽入門經典》6-7 Trees on the level UVA122——二叉樹的層次遍歷

Trees on the level       UVA - 122  Trees are fundamental in many branches of computer science (Pun definitely intended

原创 《算法競賽入門經典》6-8樹TREE UVA548——二叉樹的遞歸遍歷/深度優先遍歷DFS

You are to determine the value of the leaf node in a given binary tree that is the terminal node of a path of least val

原创 《算法競賽入門經典》6-6小球下落——二叉樹的編號

6.3.1 二叉樹的編號 6-6 Dropping Balls A number of K balls are dropped one by one from the root of a fully binary tree struc

原创 An easy problem HDU - 2055(對char和int的理解;Xcode中字符輸入分輸入法)

we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;  Give you a letter x and a number y , yo

原创 HDU - 2054 A == B ?(string操作複習)

Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".  Input each test case contains