原创 Ant(GG)

Description: 一根長度爲L釐米的木棒上有N只螞蟻,每隻螞蟻要麼向左走,要麼向右走,速度爲1釐米/秒。當兩隻螞蟻相撞時,他們會同時掉頭(掉頭時間不計)給出每隻螞蟻距離木棒左端的距離,問多少秒後,剛好所有螞蟻都從木棒上

原创 Bucket sort 桶排序(含EOF)

Description: Input a couple of numbers (0~100) and end of EOF. If number > 20, it shuold be mapped to [0, 20],whit

原创 函數與遞歸練習

Description: 請實現下面兩個函數,分別完成對兩個數求最大公約數,和求一個數階乘的求解。 要求:兩個函數都需要遞歸實現求解,否則本題按0分處理。主函數已給出如下: #include<stdio.h> // func

原创 eggs(遞歸)

Description: Erin買了不少雞蛋,她發現一天喫不完這麼多,於是決定把n個同樣的雞蛋放在m個同樣的籃子裏,允許有的籃子空着不放,請問共有多少種不同的放法呢? 注意:2,1,1和1,2,1 是同一種分法。 Input

原创 Pascal triangle (楊輝三角)製表符

Description: By using two-dimensional array, write C program to display a table that represents a Pascal triangle

原创 【Algorithms】NP-complrte problem(exercises-8.14)

習題解答 題目 8.14 證明此問題是NP完全的:給定一個無向圖G=(V,E)和一個整數k,求G中一個規模爲k的團以及一個規模爲k的獨立集(假設存在)。 題解 考慮將最大團問題規約到此問題:假設已有一個無向圖G=(V,E),其中有

原创 挑戰高樓(斐波那契非遞歸實現)

Description: Jeremy想要參加廣州塔的垂直馬拉松活動,然而Jeremy發現在爬樓梯的過程中有不同的方式:他可以一次走1級臺階,也可以一次走2級臺階。 現在Jeremy準備在學校的樓梯進行練習準備,請問你可以算出

原创 sicily 1007. To and Fro(破譯密碼)

Description: 題目大意:Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number

原创 【leetcode】最長連續序列(unordered_map的使用)

128. Longest Consecutive Sequence leetcode題目描述 題目描述: Given an unsorted array of integers, find the length of the long

原创 【leetcode】有重複的旋轉排序數組查找(二分)

81. Search in Rotated Sorted Array II leetcode題目描述 題目描述: Follow up for “Search in Rotated Sorted Array”: What if dupli

原创 【leetcode】搜索範圍(二分查找升序數組target元素上下界)

34. Search for a Range leetcode題目描述 題目描述: Given an array of integers sorted in ascending order, find the starting and

原创 【leetcode】二叉樹後序遍歷(stack)

145. Binary Tree Postorder Traversal leetcode題目 題目描述 Given a binary tree, return the postorder traversal of its nodes’

原创 【leetcode】Reverse Integer(考慮溢出問題)

7. Reverse Integer leetcode題目 題目描述 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123

原创 【Algorithms】NP-complete problems(exersises-8.8)

習題解答 題目 8.8 在EXACT 4SAT問題中,輸入爲一組子句,每個子句都恰爲4個literal的析取,且每個變量最多在每個子句中出現一次。目標是求其satisfying assignment(若其確實存在)。證明EXACT 4SA

原创 合併字符串(動態內存申請)

Description: 合併兩個字符串,每個字符串長度不小於1不超過50, 主函數已經給出,在join.h頭文件中完成join函數,函數原型如下: char* join(char* a, int alength, char* b,