原创 判斷平面上一點是否在三角形內 Inside a triangle or not

平面內有一個三角形,三個頂點ABC的座標已經給出。現在給出一個座標點K,要求判斷這個點是在三角形內部還是外部。注意在三角形的三邊上也算是在內部。 方法: 1、面積法 點K和三角形三頂點中的任意兩點組合成三個不同的三角形,KAB、KBC、K

原创 A-star路徑搜索

    啓發式搜索在於當前搜索結點往下選擇下一步結點時,可以通過一個啓發函數來進行選擇,選擇代價最少的結點作爲下一步搜索結點而跳轉其上。     DFS和BFS在展開子結點時均屬於盲目型搜索,它不會選擇哪個結點在下一次搜索中更優而去跳

原创 Linux下的C語言線程池

    線程池的目的是爲了減少線程創建、銷燬所帶來的代價,當有非常多的任務需要獨立的線程去做時,可以使用線程池,從線程池中獲取線程來處理一個個任務。     本文就來實現一個線程池。實現環境爲Linux操作系統,採用C語言實現pthrea

原创 shell登錄實現自動交互

每次登錄ssh時輸入密碼感覺好麻煩,於是藉助expect工具來實現密碼的自動輸入。 創建如下的login2ssh.exp腳本。 #!/usr/bin/expect set password denglumima

原创 Leetcode: 相關子查詢

Leetcode : Employees Earning More Than Their Managers +—-+——-+——–+———–+ | Id | Name | Salary | ManagerId | +—-+——-+—

原创 Euler: Digit fifth powers

Problem 30: Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

原创 Leetcode: Second Highest Salary

Write a SQL query to get the second highest salary from the Employee table. +—-+——–+ | Id | Salary | +—-+——–+ | 1 |

原创 Euler: Names scores

Problem 22: Using names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphab

原创 printf趣味程序

下面這個單行程序裏包含了不少知識,看看它會輸出什麼內容: main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);} 1:unix默認值:unix下的一些編

原创 Leetcode: find all duplicate

Leetcode : Duplicate Emails Write a SQL query to find all duplicate emails in a table named Person. +—-+———+ | Id | E

原创 學習JavaScript的閉包

從外部訪問函數局部變量 變量有局部變量和全局變量。對於函數的局部變量,在函數內部可以訪問,在函數外部無法訪問。對於全局變量,在函數內部和外部都可以訪問。 閉包是什麼? Javascript允許在函數中定義內部函數,將內部函數返回,這時候會

原创 Leetcode: Consecutive Numbers

Write a SQL query to find all numbers that appear at least three times consecutively. +—-+—–+ | Id | Num | +—-+—–+

原创 數組的最大子數組積 Maximum Product Subarray

題目:Find the contiguous subarray within an array (containing at least one number) which has the largest product. For ex

原创 尋找循環有序數組的最小值 Find Minimum in Rotated Sorted Array

題目一:Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5

原创 Leetcode : Customers Who Never Order

Now we’ve got two table. One customer table for customerid and their names, One Order tablefor customers’ Id that bough