原创 HackerRank Self Balancing Tree(AVL樹)
題目鏈接 AVL-維基百科 /* Node is defined as : typedef struct node { int val; struct node* left; struct node* right
原创 DSOJ Kth Number(第k大的數)
題目鏈接 #include<stdio.h> //查找數組中第k小的元素 #define MAX 100 /* 算法思想: 模仿快排的做法,首先去數組中任何一個元素(不妨取第一個),將數組分爲兩部分,s[0,..p-1],和s[p+1
原创 DSOJ Huffman coding tree(Huffman編碼樹)
題目鏈接 #include<stdio.h> //Huffman coding tree #include<string.h> #include<stdlib.h> #define MAX 200 //The maximum nu
原创 51Nod 逆序數
題目鏈接 #include<stdio.h> //求逆序數 #define MAX 50001 /* 算法思想: 利用歸併排序的算法思想:歸併排序是將帶排序序列分爲若干個子序列,每個子序列是有序的, 然後再把有序的子序列逐步合併成爲
原创 HackerRank Reverse a linked list(逆置鏈表)
題目鏈接 /* Reverse a linked list and return pointer to the head The input list will have at least one element Nod
原创 DSOJ Addition of Polynomial(多項式求和)
題目鏈接 #include<stdio.h> //多項式的加法 #include<stdlib.h> //多項式本身可能不是最簡的情況,即需要合併多項式冪指數相同的項 typedef struct node { int coef
原创 51Nod 大數乘法
題目鏈接 #include<stdio.h> //大數乘法#include<string.h> void Calc(char *s1, char *s2){ int a[2001], i, j, len1, len2; for (
原创 LeetCode Merge Sorted Array(合併有序數組)
題目鏈接 #include<stdio.h> //Merge Sorted Array /* 算法思想: 利用插入排序的算法思想,依次遍歷nums2中的每一個元素,並將其插入到有序的nums1中 */ void merge(int
原创 DSOJ Specular reflection of a tree(樹的鏡面映射)
題目鏈接 #include<stdio.h> //Specular reflection of a tree #include<string.h> #include<stdlib.h> #define MAX 100 //樹的
原创 DSOJ Sliding Window
題目鏈接 #include<stdio.h> //Sliding Window #include<stdlib.h> /* 算法思想: 選擇單調隊列的數據結構 對於求最小值而言,建立隊列元素遞增的單調隊列,隊首保存的即爲最小值,在
原创 DSOJ BST(二叉搜索樹)
題目鏈接 #include<stdio.h> //Binary Search Tree #include<stdlib.h> typedef struct node { int data; struct node *left,
原创 LeetCode Sort List(鏈表排序)
題目鏈接 struct ListNode *MergeSortList(struct ListNode *head1, struct ListNode *head2) { struct ListNode *p1, *p2, *p, *
原创 HackerRank Huffman Decoding(Huffman解碼)
題目鏈接 /* The structure of the node is typedef struct node { int freq; char data; node * left; node *
原创 51Nod A^BmodC
題目鏈接 #include<stdio.h> //二分快速冪 int Mod(int a, int b, int c) { long long ans = 1; long long base = a; while (b != 0
原创 HackerRank Truck Tour
題目鏈接 #include<stdio.h> int FindMin(int *queue, int n) { long long sum = 0; int i = 0, j = 0; for (; i < n; i++) {