2009年4月27日

String... array...

如果是有關string的題目,多半是講求效率
而最好的效率應該就是linear time(至少在類似interview problems中)
至於buffer也是能省就省,避免allocate unnecessary space
所以值得注意兩點:
1. Avoid redundant shift due to character removal
2. Use ASCII array (by default definition) instead of character comparison
此外也可以用swap頭尾兩端的方法來reverse a string

題外話:dynamic programming可看作是recursion with caching
避免重覆計算一樣的東西
Algorithm design should consider both (1) base case and (2) recursive case
By the way, recursion can be inefficient while filling the call stack by explicitly returning desired answers. see more from Tail recursion.
... Read more

2009年4月25日

When a programmer needs some art

Better Programmer Art (or how to fake it as a game artist)

此文告訴我們"輕輕鬆鬆當(偽)美術"的一些方法
但在我看來,除了改變一些基本遊戲想法,要讓遊戲畫面OK(至少吸引我)也不是太容易的
創意為本,工時還是難省

附上以我用滑鼠所畫的圖做結論:





















GUI裡只有按鈕是自己畫的(That is what I am talking about...)

... Read more

2009年1月12日

vector, deque, and list

From: http://www.gotw.ca/gotw/054.htm

1. A deque offers constant-time insert() and erase() operations at the front of the container, whereas a vector does not -- hence the note in the Standard about using a deque if you need to insert or erase at both ends of the sequence.

2. A deque uses memory in a more operating system-friendly way, particularly on systems without virtual memory. For example, a 10-megabyte vector uses a single 10-megabyte block of memory, which is usually less efficient in practice than a 10-megabyte deque that can fit in a series of smaller blocks of memory.

3. A deque is easier to use, and inherently more efficient for growth, than a vector. The only operations supplied by vector that deque doesn't have are capacity() and reserve() -- and that's because deque doesn't need them! For vector, calling reserve() before a large number of push_back()s can eliminate reallocating ever-larger versions of the same buffer every time it finds out that the current one isn't big enough after all. A deque has no such problem, and having a deque::reserve() before a large number of push_back()s would not eliminate any allocations (or any other work) because none of the allocations are redundant; the deque has to allocate the same number of extra pages whether it does it all at once or as elements are actually appended.

Also from: http://www.velocityreviews.com/forums/t280389-vector-list-and-deque.html

When you need random access to the elements of the collection, and you will be doing insertions and deletions only at the back of the container. That is the time you should prefer vector.

Finally, total explanation at: http://blog.csdn.net/qer_liu/archive/2006/05/07/711642.aspx

... Read more

2008年5月16日

語言

逐漸失去寫東西的習慣後,發現自己的文字在描述一件事情的時候,很容易顯得枯燥無味。

不禁讓我想起小說"恐懼炸彈"中,失去邏輯與語言的主角。對了,這篇小說即是之前沸沸湯湯的九把刀抄襲文。
很想說說關於抄襲與惡搞之間的不同,但現在真的就像那主角一樣,需要練習恢復語言能力。

後記:
應該還要記得有個東西叫文學,不是讓文字只能當工具的
慢慢找回來吧,像蹲馬步
新注音很爛,狒狒陽陽,好歹也該狒狒癢癢

更後記:
是沸沸湯湯「ㄕㄤ」。訂正一百遍。
... Read more

收與放

在越不適當的時候做不適當的事情,快感越大

逛到這句,真是一個切身藉口
目前的我像是失去動力地把一切置之腦後

據說爆彈要炸開前,會先牽引吸入附近所有物體,再爆裂炸開

若是空包彈就糗了。
... Read more

2008年5月2日

What for

Everything is against me, or I am against everything.
... Read more

2008年4月8日

勤為何物


最近看到Jordan的廣告,相信有練球經驗的人都了解它在講什麼。每一趟折返衝刺、每一輪跳投練習、每一滴熱血的汗水,好像都可以讓自己對著黑暗的天空大聲宣佈對勝利的執著。

No Cinderellas,而且結果不一定是笑著的。REAL中的野宮為了預想能在比賽成功最後一擊,在泡澡時不忘訓練手腕,卻因為遭退學只能看著昔日隊友慘遭敵隊派菜鳥羞辱。努力,成功,成為傳奇,不是保證的直達票。

然而我還是喜歡努力的人們。大東京玩具箱:"我認為我繼夢想和希望之後的武器,應該是努力和毅力!"

青年們立死志吧!

p.s. (其實只是自勵短文)


... Read more