發表文章

目前顯示的是 2月, 2016的文章

讀書筆記:執行力

「少了執行力,突破性思考沒有用,學習不會帶來價值,員工無法達成延展性目標,革命也會半途而廢。」 「如果不知道如何執行,領導人的努力註定會事倍功半」 「未先衡量組織的執行能力,就不可能規劃出像樣的策略。」 「千萬別把執行和戰術混為一談。」 「執行是一套系統化流程,嚴謹地探討『如何』與『是什麼』、提出質疑、不厭其煩地追蹤進度、確保權責分明。」 「唯有當領導人的心思和靈魂和公司融為一體時,這家公司才會具有執行力。」 「領導人要做好執行的工作,必須管理三項核心流程:挑選各級主管、設定策略方向、主導營運。」 「親自領導執行的工作必分事必躬親,或是專斷獨裁,不肯授權,而是一種主動的投入,進行領導人員來就該做的事。」 「執行必須成為組織文化的一部分,驅策各層級所有主管的行為。」 「一般人以為光靠聰明才智就可以有很好的成就,這種想法其實只對了一半。」 「諾貝爾得主的成功,是由於他們能精確執行某項證明的所有細節,並讓他人可重作、驗證或應用此項證明。」 「在執行的過程中,一切都會變得明確起來,你會更清楚看見企業的全貌。執行也是因應變化或轉型的最好方法,比企業文化或經營哲學都管用。」 「每當公司未能達到預定目標,最常見的解釋就是執行長得策略出了差錯。然而,策略失敗的原因大都是執行不力,而不在於策略本身。」 「承諾與成果之間的鴻溝清楚可見,但是,有一道鴻溝卻尚無人察覺,那就是『公司領導人所期望達成的目標』與『組織達成目標的能力』之間的落差。」 「實事求是乃是執行的核心所在。」 「一個領導人若是說:『我列了十項重點。』表示他根本不進入狀況。」 「有時候企業必須由新的角度來釐清優先順序。」 「即使有了簡單明確的目標,如果沒有人把他當成回事也不管用。」 「缺乏執行力的公司,許多都是因為不會評鑑員工,不懂得論功行賞,也不提拔有工作績效的優秀人才。」 「傳授經驗的技巧首重發問的藝術。提出一針見血的問題,能迫使受教者去思考、反省與發現。」 執行的三項關鍵要點 : 1. 執行是一種紀律,是策略不可分割的一環。 執行是一套系統化流程,嚴謹地探討『如何』與『是什麼』、提出質疑、不厭其煩地追蹤進度、確保權責分明。 2. 執行是企業領導人首要的工作。 領導人必須對企業的營運、人員與環境有完整的了解:也唯有透過領導人親...

Building customised Android SDK

Build Android SDK for Linux 1) . build/envsetup.sh 2) lunch custom_platform-eng 3) make -j4 sdk 4) It creates a sdk directory in out/host/linux-x86/sdk/android-sdk_eng.USERNAME_linux-x86/ 5) Copy that directory somewhere, e.g. "/etc/android-sdk-custom" 6) In Eclipse: Preferences > Android, select SDK Location and point to "/etc/android-sdk-custom", Click Apply 7) You can now create an Android application that is linked against your customised Android Platform Build Android SDK for Windows 1) sudo apt-get install mingw32 tofrodos 2) . build/envsetup.sh 3) lunch custom_platform-eng 4) make -j4 win_sdk References: http://tools.android.com/build 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

讀書心得:小,是我故意的

圖片
公司一定要上市,持續擴大嗎?針對此問題< 小,是我故意的:不擴張也成功的14個故事,7種基因 >此書提供了十四個實例,說明這些老闆們是如何抵抗外在誘惑與內心的掙扎,最後他們成功地保留想要的「自由」,可謂「不自由毋寧小」的典範阿。 ---海星的故事-- 一位女孩準備將手上的海星丟回大海。一位老人走過來對她說: 「別自找麻煩,還有成千上萬的海星,你不可能拯救所有的海星。你現在做任何事都不會改變現狀。」 女孩看著手中的海星說: 「但是對這隻海星來說,我這麼做可以改變牠的命運。」 女孩將海星丟入大海。 ---結束--- 我想這故事的精神或多或少都可以表示小巨人的精神與靈魂吧。 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

學習英文的好工具:TEDICT

圖片
TEDICT 是一套將 TED.com 上的影片整合為可聽打內容的App,主畫面 TEDICT is a mobile phone app (android & iOS) that provide dictation practice with TED.com videos. It's entry screen is 聽力練習有三種模式:TEDICT(一個一個字母輸入)、TEDICTisy(選單字輸入)、Play video(看影片) There are three options for a listening exercise: TEDICT, TEDICTisy, Play video. TEDICT模式 TEDICTisy模式 Play video模式 因為筆者不想購買此軟體,所用三種語言去給他切換: 使用英文版的Free Version,就可以在TEDICT與TEDICTisy兩種模式練習前十題囉,所以筆者就這樣子用啦。 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 264. Ugly Number II 醜數 2

題目連結 https://leetcode.com/problems/ugly-number-ii/ 。 因為 Ugly Number I 比較容易,跳過直接解此題,此題的Hint實在太好了,於是筆者寫了這樣子的解法: class Solution { public: int nthUglyNumber( int n) { if (n == 0 ) return false ; if (n == 1 ) return true ; vector< int > ugly(n); int m2, m3, m5; ugly[ 0 ] = 1 ; m2 = m3 = m5 = 0 ; int k = 1 ; while (k < n) { ugly[k] = min(ugly[m2] * 2 , min(ugly[m3] * 3 , ugly[m5] * 5 )); if ( ugly[k] == ugly[m2] * 2 ) m2++; if ( ugly[k] == ugly[m3] * 3 ) m3++; if ( ugly[k] == ugly[m5] * 5 ) m5++; k++; } return ugly[k- 1 ]; } }; 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 29. Divide Two Integers 兩數相除

題目連結 https://leetcode.com/problems/divide-two-integers/ ,題目要求不可以用乘法、除法與餘數運算子。從題目分類的Tag上,筆者看到了Binary Search後,就想到 位元運算子 ,只是筆者考慮欠周詳,因為送出後一直得到Wrong Answer阿,原來是忘了考慮Overflow的問題,於是看了 此Discuss 後,寫了如下的程式碼: class Solution { public: int divide( int dividend, int divisor) { if ( divisor == 0 ) return INT_MAX; // Handling overflow if ( dividend == INT_MIN ) { if ( divisor == - 1 ) return INT_MAX; else if ( divisor == 1 ) return INT_MIN; else return ( (divisor & 1 ) == 1 ) ? divide( dividend + 1 , divisor) : divide( dividend >> 1 , divisor >> 1 ); } if ( divisor == INT_MIN ) return 0 ; int sign = (dividend >= 0 ) ^ (divisor >= 0 ) ? - 1 : 1 ; long dEnd = abs(dividend); long dSor = abs(divisor); int quotient = 0 ; while (dEnd >= dSor) { long tmpSor = dSor, q = 1 ; while ( dEnd >= (tmpS...

LeetCode OJ: 300. Longest Increasing Subsequence 最長遞增子序列

題目連結 https://leetcode.com/problems/longest-increasing-subsequence/ ,此題用 動態規劃 解。 class Solution { public: int lengthOfLIS(vector< int >& nums) { if ( nums.size() == 0 ) return 0 ; short *best; best = new short [ nums.size() ]; best[ 0 ] = 1 ; short maxLen = 1 ; // Dynamic Programming: // if( num[i] > num[k] ) // best[i] = max(best[0] ... best[k]) for ( int i = 1 ; i < nums.size(); i++ ) { short tempBest = 0 ; //找出比數字比 num[i] 小且序列長度為最大的值 for ( int k = i - 1 ; k >= 0 ; k-- ) { if ( nums[i] > nums[k] ) { if ( tempBest < best[k] ) { tempBest = best[k]; } } } best[i] = tempBest + 1 ; if ( best[i] > maxLen ) maxLen = best[i...

C++ STL:找質數 ( Prime Number with C++ STL )

因為STL的 iteractor 算是指標(還是有差異),那麼就可以先將有可能成為質數的整數都放進vector裡,然後採 埃拉托斯特尼篩法 加上雙指標將非質數的整數給刪除。 /* Prime Number using STL */ #include <iostream> #include <functional> #include <algorithm> #include <iterator> #include <vector> using namespace std; int main ( void ) { vector< int > primes; int n; cin >> n; for ( int i= 2 ; i <= n; i++) primes.push_back(i); vector< int >::iterator primeBegin= primes.begin(), primeEnd= primes.end(); while ( primeBegin != primeEnd ) { primeEnd= remove_if ( primeBegin+ 1 , primeEnd, not1 ( bind2nd ( modulus< int >(), *primeBegin))); primeBegin++; } primes. erase ( primeEnd, primes.end()); copy( primes.begin(), primes.end(), ostream_iterator< int >( cout, " " )); cout << endl; return 0 ; } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

用Yocto Project建立樹莓派2的最小映像檔

圖片
Host OS: 14.04.1-Ubuntu x86_64 安裝 Yocto Project 所需的套件: sudo apt-get install sed wget cvs subversion git-core coreutils \      unzip texi2html texinfo libsdl1.2-dev docbook-utils gawk \      python-pysqlite2 diffstat help2man make gcc build-essential \      g++ desktop-file-utils chrpath libgl1-mesa-dev libglu1-mesa-dev \      mercurial autoconf automake groff 下載 Yocto Project 與 Raspberry Pi meta layer mkdir rpi2 cd rpi2 git clone git://git.yoctoproject.org/poky.git cd poky git clone git://git.yoctoproject.org/meta-raspberrypi 環境設定: . ./oe-init-build-env build 修改 local.conf nano conf/local.conf 增加下面兩行(如下圖): MACHINE ??= "raspberrypi2" GPU_MEM = "16" 修改 bblayers.conf nano conf/bblayers.conf 增加下面一行(如下圖): <strong>  /home/jaufranc/edev/rpi/yocto/poky/meta-raspberrypi \</strong> 產生映像檔: bitbake rpi-basic-image 映像檔 寫入 SD Card : sudo dd if = tmp / deploy / images / raspberrypi2 / rpi ...

C++語言教學:STL 概觀 ( STL Overview )

投影片下載處: C++ STL 概觀 from PingLun Liao 範例程式: http://www.4shared.com/archive/LrETKOzUba/CppStl_Example.html 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

C++語言教學:函式 Function

投影片下載處: C++ Function from PingLun Liao 範例程式: http://www.4shared.com/archive/RyA88CD0ce/CppFunctionExample.html 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

C語言教學:檔案處理 ( File Handling in C )

投影片下載處: C 檔案輸入與輸出 from PingLun Liao 範例程式: http://www.4shared.com/archive/ny8F-v2ece/C_FileIO_Example.html 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 219. Contains Duplicate II 有重複數字嗎?

題目連結 https://leetcode.com/problems/contains-duplicate-ii/ 。 此題比 LeetCode OJ: 217. Contains Duplicate 有重複數字嗎? 難一點點,不過依然用 Java 的 HashMap 來計數: public class Solution { public boolean containsNearbyDuplicate ( int [] nums , int k ) { HashMap < Integer , Integer > numbers = new HashMap <>(); for ( int idx = 0 ; idx < nums . length ; idx ++) { if ( numbers . containsKey ( nums [ idx ]) == false ) { numbers . put ( nums [ idx ], idx ); } else { int preIdx = ( int ) numbers . get ( nums [ idx ]); if ( idx - preIdx <= k ) return true ; numbers . put ( nums [ idx ], idx ); } } return false ; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 217. Contains Duplicate 有重複數字嗎?

題目連結 https://leetcode.com/problems/contains-duplicate/ , 直接用 Java 的 HashMap 來計數(這題很容易吧)。 public class Solution { public boolean containsDuplicate ( int [] nums ) { HashMap < Integer , Integer > numbers = new HashMap <>(); for ( int i = 0 ; i < nums . length ; i ++) { if ( numbers . containsKey ( nums [ i ]) == false ) { numbers . put ( nums [ i ], 1 ); } else { return true ; } } return false ; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 268. Missing Number 消失的數字

題目連結 ,因為題目剛好可以用標記的方式紀錄數字是否有出現過,所以就寫了下面的程式囉: public class Solution { public int missingNumber ( int [] nums ) { int size = nums . length + 1 ; boolean [] found = new boolean [ size ]; for ( int i = 0 ; i < size - 1 ; i ++) found [ nums [ i ] ] = true ; for ( int i = 0 ; i < size ; i ++) if ( found [ i ] == false ) return i ; return size ; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 287. Find the Duplicate Number 找重複出現的數字

題目連結 ,筆者採取跟 Single Number , Single Number II , Single Number III 相同解法: public class Solution { public int findDuplicate ( int [] nums ) { int target = 0 ; HashMap < Integer , Integer > numbers = new HashMap <>(); for ( int i = 0 ; i < nums . length ; i ++) { if ( numbers . containsKey ( nums [ i ]) == false ) { numbers . put ( nums [ i ], 1 ); } else { target = nums [ i ]; break ; } } return target ; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 204. Count Primes 計算質數個數

圖片
題目連結 ,此題在Wiki上有個 埃拉托斯特尼篩法 : Input : an integer n > 1 Let A be an array of Boolean values, indexed by integers 2 to n , initially all set to true . for i = 2, 3, 4, ..., not exceeding √ n : if A [ i ] is true : for j = i 2 , i 2 +i , i 2 +2i , i 2 +3i , ..., not exceeding n  : A [ j ] := false Output : all i such that A [ i ] is true . Wiki上還有動畫說明: public class Solution { public int countPrimes ( int n ) { boolean [] primes = new boolean [ n ]; for ( int i = 2 ; i < n ; i ++) primes [ i ] = true ; for ( int i = 2 ; i * i < n ; i ++) { if ( primes [ i ] ) for ( int j = i * i ; j < n ; j = j + i ) primes [ j ] = false ; } int primeCnt = 0 ; for ( int i = 0 ; i < n ; i ++) if ( primes [ i ]) primeCnt ++; return primeCnt ; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

讀書心得:誰說人是理性的!

< 誰說人是理性的! >此書用嚴謹的科學方法:統計的方式。來驗證人到底是不是理性的,書中提到一個觀念-->比較是相對的,此點在商場上更是常見。另外還有預期心理的效應,預期心理是不是失望的來源之一呢? 底下附上作者在 TED 上的演講: 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 260. Single Number III 尋找出現一次的數字

題目連結 ,和 LeetCode OJ: 136. Single Number 與 LeetCode OJ: 137. Single Number II 相同的想法,加上一些變化就解題了。 public class Solution { public int [] singleNumber ( int [] nums) { HashMap<Integer, Integer> numbers = new HashMap<>(); for ( int i = 0 ; i < nums. length ; i++) { if ( numbers. containsKey (nums[i]) == false ) { numbers. put (nums[i], 1 ); } else { numbers. remove (nums[i]); } } int [] target = new int [numbers. size ()]; int i = 0 ; for (Integer key : numbers. keySet ()) { target[i] = key. intValue (); i++; } return target; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 137. Single Number II 尋找出現一次的數字

題目連結 ,筆者採和 LeetCode OJ: 136. Single Number 一樣的想法,這樣子就很好解題囉。 public class Solution { public int singleNumber ( int [] nums) { int target = 0 ; HashMap<Integer, Integer> numbers = new HashMap<>(); for ( int i = 0 ; i < nums. length ; i++) { if ( numbers. containsKey (nums[i]) == false ) { numbers. put (nums[i], 1 ); } else { numbers. put (nums[i], 2 ); } } for (Integer key : numbers. keySet ()) { if ( numbers. get (key) == 1 ) { target = key. intValue (); break ; } } return target; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 136. Single Number 尋找出現一次的數字

題目連結 ,筆者的想法很簡單,就是用Java裡含有 <Key, Value> 的Data Structure,利用Key來作檢查有無重複資料的出現,在 Discuss 裡頭,有用XOR的作法,只不過筆者所想為:【 若所要找的資料型態不是Integer時,要怎麼解題? 】 import java.util.HashMap ; public class Solution { public int singleNumber ( int [] nums) { int target = 0 ; HashMap<Integer, Integer> numbers = new HashMap<>(); for ( int i = 0 ; i < nums. length ; i++) { if ( numbers. containsKey (nums[i]) == false ) { numbers. put (nums[i], 1 ); } else { numbers. remove (nums[i]); } } for (Integer key : numbers. keySet ()) { target = key. intValue (); } return target; } } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 191. Number of 1 Bits (Hamming weight) 漢明重量

題目連接 ,筆者一開始很單純一個一個bit去算: int hammingWeight ( uint32_t n) { int bitCnt = 0 ; uint32_t v = n; while ( v > 0 ) { if ( v & 0x01 ) bitCnt ++ ; v = v >> 1 ; } return bitCnt; } 但看了 Discuss 後,才知道原來在 Wiki 上有幾種比較快速的解法,底下列出筆者比較容易理解的版本: //This is better when most bits in x are 0 //It uses 3 arithmetic operations and one comparison/branch per "1" bit in x. int popcount_4 ( uint64_t x ) { int count ; for ( count = 0 ; x ; count ++ ) x &= x - 1 ; return count ; } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 292. Nim Game

題目連結 ,這題的分析結果如下: 1 5  9 13 ... ==> 1 You Win. 2 6 10 14 ... ==> 2 You Win. 3 7 11 15 ... ==> 3 You Win. 4 8 12 16 ... ==> 0 You lost. 所以程式碼也很簡單: class Solution { public: bool canWinNim( int n) { return n % 4 ; } }; 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LeetCode OJ: 12. Integer to Roman 十進制整數轉成羅馬數字

題目連結 ,此題跟 LintCode: Roman to Integer 羅馬數字轉成十進制整數 剛好相反,直接用查表法解: class Solution { public: string intToRoman( int num) { if ( num == 0 ) return "0" ; string romanSymbol[ 4 ][ 10 ] = { { "0" , "I" , "II" , "III" , "IV" , "V" , "VI" , "VII" , "VIII" , "IX" }, { "0" , "X" , "XX" , "XXX" , "XL" , "L" , "LX" , "LXX" , "LXXX" , "XC" }, { "0" , "C" , "CC" , "CCC" , "CD" , "D" , "DC" , "DCC" , "DCCC" , "CM" }, { "0" , "M" , "MM" , "MMM" } }; int romanValue[ 4 ] = { 1 , 10 , 100 , 1000 }; string romanStr; int tmpN = num; ...

LeetCode OJ: 258. Add Digits數根

圖片
題目連結 , Wiki 的說明: 數根是將一正整數的各個位數相加(即橫向相加),若加完後的值大於 10 的話,則繼續將各位數進行橫向相加直到其值小於 十 為止,或是,將一數字重複做數字和,直到其值小於十為止,則所得的值為該數的 數根 。 例如54817的數根為 7 ,因為5+4+8+ 1 +7=25,25大於10則再加一次,2+5=7,7小於十,則7為54817的數根。 由上述說明可能會讓人寫出一個每個位數相加的程式吧,不過其實有 公式可以解 的: 所以程式碼就很短又很快啦。 1 2 3 4 5 6 class Solution { public: int addDigits( int num) { return num - 9 * (floor( (num - 1 ) / 9 )); } }; 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

LintCode: Space Replacement 替換空白

題目連結 https://www.lintcode.com/problem/space-replacement/description 。 一開始我就試看看只算出替換後的新字串長度,結果 Wrong Answer 。 而且題目要求Do it in-place,分明就是指標的基本題。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 class Solution { public: /** * @param string: An array of Char * @param length: The true length of the string * @return: The true length of new string */ int replaceBlank( char string[], int length) { // Write your code here int newStrLen = length; const int SHIFT_INC = 2 ; for ( int i = 0 ; i < newStrLen; i ++ ) { if ( string[i] == ' ' ) { newStrLen += SHIFT_INC; // Shifting the remaining character for ( int j = newStrLen; j >= i; j -- ) string[j] = string[j - SHIFT_INC]; string[i] = '%' ; string[i + 1 ] = '2' ; ...